結果

問題 No.487 2017 Calculation(2017の計算)
ユーザー kohaku_kohaku
提出日時 2017-02-25 02:11:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 2,625 ms
コンパイル使用メモリ 76,324 KB
実行使用メモリ 41,688 KB
最終ジャッジ日時 2025-01-03 08:35:12
合計ジャッジ時間 5,460 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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