結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
atkrym
|
| 提出日時 | 2016-11-07 15:46:35 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,532 bytes |
| コンパイル時間 | 2,276 ms |
| コンパイル使用メモリ | 79,840 KB |
| 実行使用メモリ | 139,044 KB |
| 最終ジャッジ日時 | 2024-11-25 03:53:42 |
| 合計ジャッジ時間 | 76,014 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 2 TLE * 1 OLE * 11 |
ソースコード
import java.util.*;
public class Main {
private static Scanner sc = new Scanner(System.in);
private static long[] ary;
public static void main(String[] args) throws Exception {
long x = nextLong();
int n = nextInt();
ary = nextLong(n);
long ans = 0;
for (int i = 0;i < n;i++) {
ans += pow(x, ary[i])%1000003;
}
System.out.println(ans);
}
private static long pow(long n, long p) {
long ans;
if (p==0) return 1;
if (p==1) return n;
if (p==2) return n*n;
if (p%2==0) {
ans = pow(n,p/2)*pow(n,p/2);
} else {
ans = pow(n,p/2)*pow(n,p/2)*n;
}
System.out.println(n+" "+p+" "+ans);
return ans%1000003;
}
private static int nextInt() { return sc.nextInt(); }
private static long nextLong() { return sc.nextLong(); }
private static float nextFloat() { return sc.nextFloat(); }
private static int[] nextInt(int n) {
int[] ret = new int[n];
for (int i = 0;i < n;i++) {
ret[i] = nextInt();
}
return ret;
}
private static long[] nextLong(int n) {
long[] ret = new long[n];
for (int i = 0;i < n;i++) {
ret[i] = nextLong();
}
return ret;
}
private static float[] nextFloat(int n) {
float[] ret = new float[n];
for (int i = 0;i < n;i++) {
ret[i] = nextFloat();
}
return ret;
}
}
atkrym