結果

問題 No.487 2017 Calculation(2017の計算)
ユーザー tenten
提出日時 2020-09-28 21:49:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 466 bytes
コンパイル時間 2,860 ms
コンパイル使用メモリ 73,944 KB
実行使用メモリ 41,284 KB
最終ジャッジ日時 2024-07-02 16:45:45
合計ジャッジ時間 4,998 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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();
		int ans = 2017 % m + pow(pow(2017 % m, 2, m), 2017, m);
		ans %= m;
		System.out.println(ans);
	}
	
	static int pow(int x, int p, int m) {
	    if (p == 0) {
	        return 1;
	    } else if (p % 2 == 0) {
	        return pow(x * x % m, p / 2, m);
	    } else {
	        return pow(x, p - 1, m) * x % m;
	    }
	}
}
0