結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-12 03:46:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 146 ms / 5,000 ms |
| コード長 | 1,284 bytes |
| コンパイル時間 | 3,781 ms |
| コンパイル使用メモリ | 74,356 KB |
| 実行使用メモリ | 41,772 KB |
| 最終ジャッジ日時 | 2024-06-26 04:47:23 |
| 合計ジャッジ時間 | 6,342 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
import java.util.Scanner;
/**
* yukicoder no.17
* @author scache
*
*/
public class PowAddition {
public static void main(String[] args) {
PowAddition p = new PowAddition();
}
public PowAddition() {
Scanner sc = new Scanner(System.in);
long x = sc.nextLong();
int n = sc.nextInt();
long[] a = new long[n];
for(int i=0;i<n;i++)
a[i] = sc.nextLong();
solve(x, a);
}
public void solve(long x, long[] a) {
long res = 0;
for(int i=0;i<a.length;i++){
res += powMod(x, a[i]);
res %= 1000003;
}
System.out.println(res);
}
public long powMod(long x, long a){
long c = x;
long res = 1;
while(a>0){
if((a&1)==1)
res = (res*c)%1000003;
c = (c*c)%1000003;
a = a>>1;
}
return res;
}
// フェルマーの小定理を使う方法
// #include <iostream>
// #include <algorithm>
// using namespace std;
// #define REP(i, n) for(int(i)=0;(i)<(n);++(i))
// typedef unsigned long long ull;
// int x, N, a, MOD = 1000003;
// ull res;
// int n[1000003];
//
// int main(){
// cin >> x >> N;
// n[0] = 1;
// REP(i,MOD) n[i+1] = (n[i] * x) % MOD;
// REP(i,N){ cin >> a; res += n[a%(MOD-1)]; }
// cout << res%MOD << endl;
// return 0;
// }
}