結果

問題 No.487 2017 Calculation(2017の計算)
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-02-25 02:11:27
言語 Java19
(openjdk 21)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 3,513 ms
コンパイル使用メモリ 71,584 KB
実行使用メモリ 56,268 KB
最終ジャッジ日時 2023-09-01 22:01:37
合計ジャッジ時間 5,490 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,904 KB
testcase_01 AC 120 ms
55,764 KB
testcase_02 AC 118 ms
55,996 KB
testcase_03 AC 118 ms
54,480 KB
testcase_04 AC 120 ms
55,820 KB
testcase_05 AC 119 ms
55,796 KB
testcase_06 AC 117 ms
55,908 KB
testcase_07 AC 114 ms
55,948 KB
testcase_08 AC 119 ms
56,268 KB
testcase_09 AC 118 ms
55,636 KB
testcase_10 AC 114 ms
55,876 KB
testcase_11 AC 116 ms
55,880 KB
testcase_12 AC 118 ms
55,532 KB
testcase_13 AC 118 ms
56,048 KB
testcase_14 AC 115 ms
56,072 KB
testcase_15 AC 116 ms
56,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        long A = 2017;
        long B = powmod(A*A,A,M);
        long ans = (A%M+B)%M;
        System.out.println(ans);
    }
    static long powmod(long A, long k, long M){
        if(k==0)return 1;
        if(k%2==0){
            return powmod(A*A%M,k/2,M)%M;
        }else{
            return A*powmod(A,k-1,M)%M;
        }
    }
}
0