結果

問題 No.344 ある無理数の累乗
ユーザー mits58mits58
提出日時 2016-07-09 00:51:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 766 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 77,312 KB
実行使用メモリ 41,528 KB
最終ジャッジ日時 2024-04-21 09:02:20
合計ジャッジ時間 7,101 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
41,128 KB
testcase_01 AC 122 ms
41,088 KB
testcase_02 AC 115 ms
41,124 KB
testcase_03 AC 119 ms
41,080 KB
testcase_04 AC 119 ms
41,360 KB
testcase_05 AC 108 ms
40,112 KB
testcase_06 AC 120 ms
41,356 KB
testcase_07 AC 120 ms
41,056 KB
testcase_08 AC 121 ms
40,832 KB
testcase_09 AC 105 ms
39,924 KB
testcase_10 AC 116 ms
41,296 KB
testcase_11 AC 114 ms
40,344 KB
testcase_12 AC 121 ms
41,256 KB
testcase_13 AC 120 ms
41,528 KB
testcase_14 AC 124 ms
41,256 KB
testcase_15 AC 107 ms
39,932 KB
testcase_16 AC 113 ms
40,684 KB
testcase_17 AC 103 ms
39,952 KB
testcase_18 AC 117 ms
41,000 KB
testcase_19 AC 119 ms
41,160 KB
testcase_20 AC 118 ms
41,148 KB
testcase_21 AC 121 ms
41,116 KB
testcase_22 AC 124 ms
41,056 KB
testcase_23 AC 105 ms
39,748 KB
testcase_24 AC 116 ms
41,196 KB
testcase_25 AC 110 ms
40,612 KB
testcase_26 AC 120 ms
41,144 KB
testcase_27 AC 119 ms
40,960 KB
testcase_28 AC 120 ms
40,848 KB
testcase_29 AC 123 ms
41,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main{
	static int[][] I={{1,0},{0,1}};
	static int mod=1000;
	static int[][] pow(int[][] a,int x){
		if(x==1 || x==0) return a;
		else if(x%2==0) return pow(mul(a,a),x/2);
		else return mul(pow(mul(a,a),x/2),a);
	}
	static int[][] mul(int[][] a,int[][] b){
		int[][] res=new int[2][2];
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
					res[i][j]+=a[i][k]*b[k][j];
					res[i][j]%=mod;
				}
			}
		}
		return res;
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int[][] a={{1,3},{1,1}};
			int[][] ans=pow(a,n);
			if(n==0) System.out.println(1);
			else System.out.println((2*ans[0][0]+(n%2==0 ? -1 : 0))%mod);
		}
	}
}
0