結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
kohaku_kohaku
|
| 提出日時 | 2016-11-17 22:56:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 656 bytes |
| コンパイル時間 | 2,120 ms |
| コンパイル使用メモリ | 74,112 KB |
| 実行使用メモリ | 46,912 KB |
| 最終ジャッジ日時 | 2024-11-26 03:13:30 |
| 合計ジャッジ時間 | 4,759 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 WA * 12 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long x = sc.nextLong();
int N = sc.nextInt();
long mod = 1000003;
long sum=0;
for(int i=0; i<N; i++){
long a = sc.nextInt();
sum+=pow(x,a,mod);
}
System.out.println(sum);
}
static long pow(long x, long n, long m){
if(n==0){
return 1;
}else if(n%2==1){
long r = x*pow(x*x,n/2,m)%m;
return r;
}else{
long r = pow(x*x,n/2,m)%m;
return r;
}
}
}
kohaku_kohaku