結果
問題 | No.1161 Many Powers |
ユーザー | tenten |
提出日時 | 2022-08-04 16:00:18 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,523 bytes |
コンパイル時間 | 4,709 ms |
コンパイル使用メモリ | 74,428 KB |
実行使用メモリ | 52,460 KB |
最終ジャッジ日時 | 2023-10-12 13:41:22 |
合計ジャッジ時間 | 8,370 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,320 KB |
testcase_01 | AC | 44 ms
49,160 KB |
testcase_02 | AC | 45 ms
49,356 KB |
testcase_03 | AC | 46 ms
49,360 KB |
testcase_04 | AC | 43 ms
49,200 KB |
testcase_05 | AC | 56 ms
50,396 KB |
testcase_06 | AC | 57 ms
50,388 KB |
testcase_07 | AC | 44 ms
49,268 KB |
testcase_08 | AC | 97 ms
50,316 KB |
testcase_09 | AC | 101 ms
50,368 KB |
testcase_10 | AC | 72 ms
50,460 KB |
testcase_11 | AC | 88 ms
50,544 KB |
testcase_12 | AC | 69 ms
50,672 KB |
testcase_13 | AC | 113 ms
50,408 KB |
testcase_14 | AC | 153 ms
49,588 KB |
testcase_15 | AC | 145 ms
51,604 KB |
testcase_16 | AC | 164 ms
51,728 KB |
testcase_17 | AC | 119 ms
50,388 KB |
testcase_18 | AC | 98 ms
50,496 KB |
testcase_19 | AC | 79 ms
50,276 KB |
testcase_20 | AC | 165 ms
52,460 KB |
testcase_21 | AC | 81 ms
50,656 KB |
testcase_22 | AC | 158 ms
50,868 KB |
testcase_23 | AC | 43 ms
49,356 KB |
testcase_24 | AC | 44 ms
49,392 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long a = sc.nextLong(); long b = sc.nextLong(); int c = sc.nextInt(); long[] counts = new long[c]; Arrays.fill(counts, a / c); for (int i = 1; i <= a % c; i++) { counts[i]++; } long ans = 0; for (int i = 1; i < c; i++) { ans += pow(i, b, c) * counts[i] % c; ans %= c; } System.out.println(ans); } static long pow(long x, long p, int m) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % m, p / 2, m); } else { return pow(x, p - 1, m) * x % m; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }