結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
kuramu
|
| 提出日時 | 2016-01-29 11:17:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 5,000 ms |
| コード長 | 926 bytes |
| コンパイル時間 | 2,477 ms |
| コンパイル使用メモリ | 74,888 KB |
| 実行使用メモリ | 46,372 KB |
| 最終ジャッジ日時 | 2024-06-26 05:07:54 |
| 合計ジャッジ時間 | 4,060 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
try {
String[] temp1 = stdReader.readLine().split(" ");
int x = Integer.parseInt(temp1[0]);
int N = Integer.parseInt(temp1[1]);
String[] temp2 = stdReader.readLine().split(" ");
int ans = 0;
for(int i=0;i<N;i++){
ans = (ans + pow(x, Integer.parseInt(temp2[i]))) % 1000003;
}
System.out.println(ans);
} catch (IOException e) {
e.printStackTrace();
}
}
public static int pow(int x,int n){
long temp = x;
long ans = 1;
while(n>0){
if(n%2==0){
temp = temp*temp % 1000003;
n /= 2;
}else{
n -= 1;
ans = ans *temp % 1000003;
}
}
return (int)ans;
}
}
kuramu