結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2016-11-17 23:30:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 141 ms / 5,000 ms |
コード長 | 699 bytes |
コンパイル時間 | 2,042 ms |
コンパイル使用メモリ | 74,032 KB |
実行使用メモリ | 41,680 KB |
最終ジャッジ日時 | 2024-06-26 05:18:23 |
合計ジャッジ時間 | 4,590 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
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 m = 1000003;long sum=0;for(int i=0; i<N; i++){long a = sc.nextInt();sum+=pow(x,a);sum%=m;}System.out.println(sum);}static long pow(long x, long n){long m = 1000003;x%=m;if(n==0){return 1;}else if(n%2==1){long r = pow(x,n-1)%m;return x*r%m;}else{long r = pow(x,n/2)%m;return r*r%m;}}}