結果

問題 No.1161 Many Powers
ユーザー tentententen
提出日時 2024-02-06 11:52:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 2,551 ms
コンパイル使用メモリ 79,596 KB
実行使用メモリ 55,796 KB
最終ジャッジ日時 2024-02-06 11:53:02
合計ジャッジ時間 7,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
55,020 KB
testcase_01 AC 75 ms
55,128 KB
testcase_02 AC 73 ms
54,892 KB
testcase_03 AC 77 ms
55,396 KB
testcase_04 AC 74 ms
54,988 KB
testcase_05 AC 89 ms
55,676 KB
testcase_06 AC 89 ms
55,648 KB
testcase_07 AC 75 ms
55,004 KB
testcase_08 AC 130 ms
55,780 KB
testcase_09 AC 131 ms
55,768 KB
testcase_10 AC 103 ms
55,796 KB
testcase_11 AC 120 ms
55,768 KB
testcase_12 AC 101 ms
55,736 KB
testcase_13 AC 156 ms
55,776 KB
testcase_14 AC 171 ms
55,768 KB
testcase_15 AC 169 ms
55,784 KB
testcase_16 AC 185 ms
55,772 KB
testcase_17 AC 170 ms
55,784 KB
testcase_18 AC 132 ms
55,780 KB
testcase_19 AC 113 ms
55,772 KB
testcase_20 AC 211 ms
55,772 KB
testcase_21 AC 112 ms
55,640 KB
testcase_22 AC 175 ms
55,672 KB
testcase_23 AC 75 ms
55,016 KB
testcase_24 AC 74 ms
55,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 div = a / c % c;
        long mod = a % c;
        long ans = IntStream.range(1, c).mapToLong(i -> pow(i, b, c) * (i <= mod ? div + 1 : div) % c)
            .reduce(0, (x, y) -> (x + y) % c);
        System.out.println(ans);
    }
    
    static long pow(long x, long p, int mod) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % mod, p / 2, mod);
        } else {
            return pow(x, p - 1, mod) * x % mod;
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0