結果

問題 No.16 累乗の加算
ユーザー tentententen
提出日時 2024-02-05 13:53:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,580 bytes
コンパイル時間 2,454 ms
コンパイル使用メモリ 80,248 KB
実行使用メモリ 55,012 KB
最終ジャッジ日時 2024-02-05 13:53:07
合計ジャッジ時間 4,681 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
54,888 KB
testcase_01 AC 69 ms
54,892 KB
testcase_02 AC 72 ms
55,012 KB
testcase_03 AC 72 ms
55,008 KB
testcase_04 AC 72 ms
54,892 KB
testcase_05 AC 73 ms
55,004 KB
testcase_06 AC 72 ms
54,880 KB
testcase_07 AC 72 ms
54,892 KB
testcase_08 AC 73 ms
54,896 KB
testcase_09 AC 72 ms
54,900 KB
testcase_10 AC 71 ms
54,904 KB
testcase_11 AC 68 ms
54,864 KB
testcase_12 AC 71 ms
54,872 KB
testcase_13 AC 73 ms
55,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000003;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int target = sc.nextInt();
        int n = sc.nextInt();
        long ans = IntStream.range(0, n).mapToLong(i -> pow(target, sc.nextInt()))
            .reduce(0, (a, b) -> (a + b) % MOD);
        System.out.println(ans);
    }
    
    static long pow(long x, int 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 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