結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
SagToki
|
| 提出日時 | 2018-05-29 13:26:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,452 bytes |
| コンパイル時間 | 3,365 ms |
| コンパイル使用メモリ | 78,712 KB |
| 実行使用メモリ | 54,392 KB |
| 最終ジャッジ日時 | 2024-06-30 08:01:18 |
| 合計ジャッジ時間 | 10,311 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 11 |
ソースコード
import java.math.BigDecimal;
import java.util.Scanner;
import java.util.InputMismatchException;
public class AdditionOfPowers {
public static void main(String[] args){
int[] N =Input();
Processing(N);
BigDecimal Count = BigDecimal.ZERO;
for(int i = 0 ; i < N.length - 2 ; i++){
Count = Count.add(Processing(N)[i]);
}
System.out.println(Count);
}
//数値を入力して範囲が正しいかを判定するメソッド
public static int[] Input(){
Scanner scanner = new Scanner(System.in);
int X = scanner.nextInt();
int N = scanner.nextInt();
int[] Store = new int[N + 2];
Store[0] = X;
Store[1] = N;
try{
//Xの条件判定
if(X < 1 || X > 100){
System.out.println("Xは1以上100以下の数字で入力してください");
System.exit(0);
}
//Nの条件判定
if(N < 1 || N > 100){
System.out.println("Nは1以上100以下の数字で入力してください");
System.exit(0);
}
//各項の入力と条件判定
for(int i = 2 ; i < N + 2 ; i++){
int Z = scanner.nextInt();
Store[i] = Z;
if(Z < 0 || Z > Math.pow(10,8)){
System.out.println("各項は0以上10000000以下で入力してください");
System.exit(0);
}
}
}catch(InputMismatchException e){
System.out.println("数字を入力してください");
System.exit(0);
}catch(Exception E){
System.out.println("想定外のエラーです");
}
return Store;
}
//計算を実行するメソッド
public static BigDecimal[] Processing(int[] Store){
int X = Store[0];
int N = Store[1];
BigDecimal Sum = BigDecimal.ZERO ;
BigDecimal[] ans = new BigDecimal[N];
int[] NewStore = new int[N];
BigDecimal big1 = BigDecimal.valueOf(1000003);
//新しい配列に旧配列を代入するループ
for(int i = 0 ; i < N ; i++){
NewStore[i] = Store[i + 2];
}
//ans配列に各項の累乗値を代入させるループ
for(int j = 0 ; j < N ; j++){
ans[j] = BigDecimal.valueOf(X).pow(NewStore[j]).remainder(big1);
}
return ans;
}
}
SagToki