結果

問題 No.1161 Many Powers
ユーザー tentententen
提出日時 2020-08-17 11:38:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 74,956 KB
実行使用メモリ 41,568 KB
最終ジャッジ日時 2024-04-19 18:45:09
合計ジャッジ時間 6,597 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
41,424 KB
testcase_01 AC 122 ms
41,464 KB
testcase_02 AC 118 ms
40,912 KB
testcase_03 AC 121 ms
41,080 KB
testcase_04 AC 119 ms
41,160 KB
testcase_05 AC 127 ms
40,900 KB
testcase_06 AC 128 ms
40,888 KB
testcase_07 AC 109 ms
41,132 KB
testcase_08 AC 165 ms
41,552 KB
testcase_09 AC 153 ms
40,196 KB
testcase_10 AC 124 ms
40,016 KB
testcase_11 AC 149 ms
41,240 KB
testcase_12 AC 134 ms
41,272 KB
testcase_13 AC 162 ms
41,568 KB
testcase_14 AC 188 ms
41,048 KB
testcase_15 AC 192 ms
41,372 KB
testcase_16 AC 206 ms
40,400 KB
testcase_17 AC 178 ms
41,472 KB
testcase_18 AC 149 ms
41,140 KB
testcase_19 AC 130 ms
41,068 KB
testcase_20 AC 210 ms
41,196 KB
testcase_21 AC 139 ms
40,192 KB
testcase_22 AC 207 ms
40,016 KB
testcase_23 AC 122 ms
41,164 KB
testcase_24 AC 111 ms
40,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        int c = sc.nextInt();
        long div = a / c % c;
        long mod = a % c;
        long ans = 0;
        for (int i = 1; i < c; i++) {
            if (i <= mod) {
                ans += powMod(i, b, c) * (div + 1) % c;
            } else {
                ans += powMod(i, b, c) * div % c;
            }
            ans %= c;
        }
        System.out.println(ans);
   }
   
   static long powMod(long x, long y, long mod) {
       if (y == 0) {
           return 1;
       } else if (y % 2 == 0) {
           return powMod(x * x % mod, y / 2, mod);
       } else {
           return powMod(x, y - 1, mod) * x % mod;
       }
   }
}
0