結果
問題 |
No.16 累乗の加算
|
ユーザー |
![]() |
提出日時 | 2015-04-04 00:36:54 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 145 ms / 5,000 ms |
コード長 | 1,072 bytes |
コンパイル時間 | 3,535 ms |
コンパイル使用メモリ | 78,524 KB |
実行使用メモリ | 41,596 KB |
最終ジャッジ日時 | 2024-06-26 04:52:27 |
合計ジャッジ時間 | 6,201 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
//No.16 累乗の加算 import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.lang.Math.*; public class No16 { static final Scanner sc = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static void solve() { int x = sc.nextInt(); int n = sc.nextInt(); long ans = 0; for (int i=0; i<n; i++) { ans = (ans + modPow(x,sc.nextInt(),1000003))%1000003; } out.println(ans); } static long modPow(long x, long n, long m) { long ret = 1; while (n > 0) { if ((n&1) == 1) ret = ret*x %m; x = x*x %m; n >>= 1; } return ret; } public static void main(String[] args) { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); sc.close(); } static void trace(Object... o) { System.out.println(deepToString(o));} }