結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-03 17:02:16 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 131 ms / 5,000 ms |
| コード長 | 597 bytes |
| コンパイル時間 | 3,080 ms |
| コンパイル使用メモリ | 74,764 KB |
| 実行使用メモリ | 41,432 KB |
| 最終ジャッジ日時 | 2024-12-24 06:40:31 |
| 合計ジャッジ時間 | 5,532 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
import java.util.*;
import java.io.*;
import java.math.*;
public class No16 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt(), n = sc.nextInt();
long w = 1000003;
long total = 0;
for(int i = 0; i < n; i++) {
double t = pow(x, sc.nextLong(), w);
total += t;
}
System.out.println((total % w));
}
static public long pow(long x, long n, long w) {
long ans = 1;
while(n > 0) {
if((n & 1) == 1) ans = ans * x % w;
x = x * x % w;
n >>= 1;
}
return ans;
}
}