This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
int arr[]=new int [50],count=0; | |
for(int i=1;i<=25;i++){ | |
arr[count++]=(int)Math.pow(3, i); | |
arr[count++]=(int)Math.pow(4, i); | |
} | |
Arrays.sort(arr); | |
int j=0,tot=0,n=scn.nextInt(); | |
for(;j<n;j++) | |
tot+=arr[j]; | |
System.out.println(arr[j-1]+","+tot); | |
} | |
/*題目:C_SO45-易 混合數列 | |
作者:1010 | |
時間:西元 2017 年 4 月*/ | |
} |
這題就依序地將3與4的次方數1~25算出來存入陣列中(題目設定最大50代表各25個次方)
最後一定要再做排序
沒有留言:
張貼留言