結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2015-08-15 12:15:29 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 149 ms / 5,000 ms |
コード長 | 1,103 bytes |
コンパイル時間 | 2,586 ms |
コンパイル使用メモリ | 78,708 KB |
実行使用メモリ | 41,784 KB |
最終ジャッジ日時 | 2024-06-26 05:01:22 |
合計ジャッジ時間 | 4,946 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
import java.io.*; import java.util.*; public class Main { static ArrayList<Long> xs = new ArrayList(); static ArrayList<Long> xn = new ArrayList(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); long x = sc.nextLong(); pre(x); int n = sc.nextInt(); long a = 0; for (int i = 0; i < n; i++) { a += empowerment(sc.nextLong()); } System.out.println(surplus(a)); } private static long surplus(long source) { return source % 1000003; } private static long empowerment(long a) { long tmpX = 1; for (int i = xn.size() - 1; i >= 0; i--) { long tmp = xn.get(i); if (a >= tmp) { tmpX = surplus(tmpX * xs.get(i)); a = a - tmp; } } return tmpX; } private static void pre(long x) { for (long i = 1; i < 1000000000; i = i + i) { xs.add(x); xn.add(i); x = surplus(x * x); } } }