結果

問題 No.1161 Many Powers
ユーザー tentententen
提出日時 2023-08-02 08:22:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 2,111 bytes
コンパイル時間 2,831 ms
コンパイル使用メモリ 91,064 KB
実行使用メモリ 52,660 KB
最終ジャッジ日時 2024-04-20 08:00:17
合計ジャッジ時間 6,282 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,464 KB
testcase_01 AC 54 ms
50,420 KB
testcase_02 AC 54 ms
50,012 KB
testcase_03 AC 57 ms
50,244 KB
testcase_04 AC 56 ms
50,384 KB
testcase_05 AC 70 ms
51,372 KB
testcase_06 AC 71 ms
51,196 KB
testcase_07 AC 54 ms
50,320 KB
testcase_08 AC 106 ms
51,344 KB
testcase_09 AC 112 ms
51,460 KB
testcase_10 AC 85 ms
51,020 KB
testcase_11 AC 97 ms
51,284 KB
testcase_12 AC 82 ms
51,044 KB
testcase_13 AC 122 ms
51,408 KB
testcase_14 AC 163 ms
52,396 KB
testcase_15 AC 155 ms
52,512 KB
testcase_16 AC 174 ms
52,660 KB
testcase_17 AC 126 ms
51,248 KB
testcase_18 AC 109 ms
51,208 KB
testcase_19 AC 92 ms
50,920 KB
testcase_20 AC 173 ms
52,544 KB
testcase_21 AC 94 ms
50,900 KB
testcase_22 AC 157 ms
50,892 KB
testcase_23 AC 56 ms
50,440 KB
testcase_24 AC 55 ms
50,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static int MOD;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long a = sc.nextLong();
        long b = sc.nextLong();
        MOD = sc.nextInt();
        long[] values = new long[MOD];
        Arrays.fill(values, a / MOD % MOD);
        for (int i = 1; i <= a % MOD; i++) {
            values[i]++;
        }
        long ans = 0;
        for (int i = 0; i < MOD; i++) {
            ans += pow(i, b) * values[i];// % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static long pow(long x, long p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0