結果

問題 No.487 2017 Calculation(2017の計算)
ユーザー shinwisteriashinwisteria
提出日時 2017-03-20 17:20:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 3,245 ms
コンパイル使用メモリ 72,004 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2023-09-18 12:34:01
合計ジャッジ時間 5,851 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,048 KB
testcase_01 AC 120 ms
55,812 KB
testcase_02 AC 119 ms
55,864 KB
testcase_03 AC 119 ms
55,824 KB
testcase_04 AC 121 ms
55,744 KB
testcase_05 AC 120 ms
55,868 KB
testcase_06 AC 119 ms
55,792 KB
testcase_07 AC 117 ms
55,780 KB
testcase_08 AC 119 ms
55,968 KB
testcase_09 AC 118 ms
56,084 KB
testcase_10 AC 118 ms
56,084 KB
testcase_11 AC 119 ms
55,804 KB
testcase_12 AC 118 ms
55,908 KB
testcase_13 AC 118 ms
53,860 KB
testcase_14 AC 118 ms
55,936 KB
testcase_15 AC 117 ms
55,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Calc2017 {
	static int M;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		M = s.nextInt();
		s.close();
		
		int a = 2017%M;
		int b;
		
		b = Rest(a,4034);
		
		a = (a + b)%M;
		System.out.println(a);

	}
	
	static int Rest(int a,int K){
		int Q,r,Ans = 0,b;
		for(int i = 1;i <= K;i++){
			if(Math.pow(a,i) >=M){
				Q = K/i;
				r = K%i;
				b = (int)Math.pow(a, i)%M;
				Ans = (Rest(b,Q) * Rest(a,r)) % M;
				return Ans;
			}
		}
		return (int)Math.pow(a, K);
	}

}
0