結果

問題 No.344 ある無理数の累乗
ユーザー hiromi_ayasehiromi_ayase
提出日時 2016-02-13 06:18:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 3,972 ms
コンパイル使用メモリ 76,568 KB
実行使用メモリ 57,644 KB
最終ジャッジ日時 2023-10-22 04:54:28
合計ジャッジ時間 9,202 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,100 KB
testcase_01 AC 132 ms
57,112 KB
testcase_02 AC 132 ms
56,984 KB
testcase_03 AC 134 ms
57,104 KB
testcase_04 AC 130 ms
56,968 KB
testcase_05 AC 133 ms
57,464 KB
testcase_06 AC 134 ms
57,464 KB
testcase_07 AC 131 ms
57,112 KB
testcase_08 AC 133 ms
57,484 KB
testcase_09 AC 134 ms
57,604 KB
testcase_10 AC 135 ms
57,620 KB
testcase_11 AC 129 ms
57,212 KB
testcase_12 AC 134 ms
57,316 KB
testcase_13 AC 132 ms
57,504 KB
testcase_14 AC 130 ms
57,420 KB
testcase_15 AC 130 ms
57,608 KB
testcase_16 AC 132 ms
57,452 KB
testcase_17 AC 136 ms
57,484 KB
testcase_18 AC 132 ms
57,508 KB
testcase_19 AC 133 ms
57,500 KB
testcase_20 AC 132 ms
57,448 KB
testcase_21 AC 128 ms
57,232 KB
testcase_22 AC 129 ms
57,204 KB
testcase_23 AC 135 ms
57,160 KB
testcase_24 AC 131 ms
57,492 KB
testcase_25 AC 129 ms
57,460 KB
testcase_26 AC 132 ms
57,488 KB
testcase_27 AC 131 ms
57,644 KB
testcase_28 AC 130 ms
57,468 KB
testcase_29 AC 130 ms
57,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner  = new Scanner(System.in);
		int n = scanner.nextInt();
		int orgN = n;
		
		long[] x = {1, 0, 0, 1};
		long[] k = {1, 1, 3, 1};
		
		long[] tmp = k;
		while (n > 0) {
			if (n % 2 == 0) {
				mul(tmp, tmp, 1000);
				n >>= 1;
			} else {
				mul(x, tmp, 1000);
				n --;
			}
		}
		long ans = (x[0] * 2 - ((orgN % 2 == 0) ? 1 : 0)) % 1000;
		System.out.println(ans);
	}

	public static void mul(long[] mat1, long[] mat2, long mod) {
		long a = mat1[0];
		long b = mat1[1];
		long c = mat1[2];
		long d = mat1[3];

		long e = mat2[0];
		long f = mat2[1];
		long g = mat2[2];
		long h = mat2[3];

		mat1[0] = (a * e + b * g) % mod;
		mat1[1] = (a * f + b * h) % mod;
		mat1[2] = (c * e + d * g) % mod;
		mat1[3] = (c * f + d * h) % mod;
	}
}
0