結果

問題 No.16 累乗の加算
ユーザー tsunabittsunabit
提出日時 2019-09-03 17:02:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 597 bytes
コンパイル時間 3,603 ms
コンパイル使用メモリ 72,544 KB
実行使用メモリ 56,408 KB
最終ジャッジ日時 2023-08-25 20:32:48
合計ジャッジ時間 6,364 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,104 KB
testcase_01 AC 121 ms
55,984 KB
testcase_02 AC 132 ms
56,028 KB
testcase_03 AC 126 ms
55,728 KB
testcase_04 AC 128 ms
56,112 KB
testcase_05 AC 130 ms
55,808 KB
testcase_06 AC 131 ms
56,084 KB
testcase_07 AC 131 ms
55,740 KB
testcase_08 AC 133 ms
56,408 KB
testcase_09 AC 135 ms
55,828 KB
testcase_10 AC 132 ms
56,088 KB
testcase_11 AC 120 ms
55,800 KB
testcase_12 AC 131 ms
55,892 KB
testcase_13 AC 129 ms
55,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No16 {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int x = sc.nextInt(), n = sc.nextInt();
    	long w = 1000003;
    	long total = 0;
    	for(int i = 0; i < n; i++) {
    		double t = pow(x, sc.nextLong(), w);
    		total += t;
    	}
    	System.out.println((total % w));
	}
    static public long pow(long x, long n, long w) {
    	long ans = 1;
    	while(n > 0) {
    		if((n & 1) == 1) ans = ans * x % w;
    		x = x * x % w;
    		n >>= 1;
    	}
    	return ans;
    }
}
0