結果

問題 No.16 累乗の加算
ユーザー watarimaycry2watarimaycry2
提出日時 2019-12-09 22:39:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 1,019 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 72,108 KB
実行使用メモリ 57,996 KB
最終ジャッジ日時 2023-09-05 11:44:38
合計ジャッジ時間 4,805 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,024 KB
testcase_01 AC 122 ms
56,020 KB
testcase_02 AC 135 ms
57,996 KB
testcase_03 AC 129 ms
55,772 KB
testcase_04 AC 131 ms
55,908 KB
testcase_05 AC 133 ms
55,720 KB
testcase_06 AC 135 ms
56,004 KB
testcase_07 AC 132 ms
55,832 KB
testcase_08 AC 135 ms
55,464 KB
testcase_09 AC 135 ms
55,976 KB
testcase_10 AC 135 ms
53,788 KB
testcase_11 AC 128 ms
55,768 KB
testcase_12 AC 137 ms
56,172 KB
testcase_13 AC 134 ms
55,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}
        static String getStr(){return sc.next();}
        static int getInt(){return sc.nextInt();}
        static Long getLong(){return sc.nextLong();}
        static boolean isNext(){return sc.hasNext();}
        public static void main(String[] args){
          long x = getLong();
          long N = getLong();
          int mod = 1000003;
          long output = 0;
          for(int i = 0; i < N; i++){
            output += originPow(x,getLong(),mod);
            output %= mod;
          }
          myout(output);
        }
        //便利メソッド追加枠ここから
static long originPow(long x, long n,int m) {
        long ans = 1;
        while (n > 0) {
                if ((n & 1) == 1)ans = ans * x % m;
                x = x * x % m;
                n >>= 1;
        }
        return ans;
}
        //便利メソッド追加枠ここまで
}
0