結果

問題 No.492 IOI数列
ユーザー tanzakutanzaku
提出日時 2017-03-10 23:37:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 2,049 bytes
コンパイル時間 5,467 ms
コンパイル使用メモリ 75,712 KB
実行使用メモリ 58,256 KB
最終ジャッジ日時 2023-09-06 14:31:46
合計ジャッジ時間 6,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,708 KB
testcase_01 AC 127 ms
56,024 KB
testcase_02 AC 126 ms
56,052 KB
testcase_03 AC 124 ms
56,444 KB
testcase_04 AC 121 ms
56,420 KB
testcase_05 AC 118 ms
55,880 KB
testcase_06 AC 126 ms
56,040 KB
testcase_07 AC 123 ms
56,276 KB
testcase_08 AC 122 ms
55,824 KB
testcase_09 AC 123 ms
55,708 KB
testcase_10 AC 111 ms
54,340 KB
testcase_11 AC 113 ms
56,448 KB
testcase_12 AC 114 ms
55,896 KB
testcase_13 AC 110 ms
56,044 KB
testcase_14 AC 114 ms
55,972 KB
testcase_15 AC 111 ms
56,100 KB
testcase_16 AC 111 ms
56,036 KB
testcase_17 AC 113 ms
58,256 KB
testcase_18 AC 112 ms
54,524 KB
testcase_19 AC 116 ms
55,944 KB
testcase_20 AC 118 ms
56,260 KB
testcase_21 AC 122 ms
55,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class _492 {
	public static void main(String[] args) throws IOException {
		new _492().solve();
	}

	void solve() throws IOException {
		try (final Scanner in = new Scanner(System.in)) {
			long n = in.nextLong() - 1;
			
			BigInteger[][] mat = new BigInteger[][]{
				new BigInteger[]{ BigInteger.valueOf(100), BigInteger.ONE },
				new BigInteger[]{ BigInteger.ZERO, BigInteger.ONE },
			};

			BigInteger m1 = BigInteger.valueOf(1000000007);
			BigInteger m2 = new BigInteger("101010101010101010101");
			System.out.println(powmat(n, m1, mat)[0][0].add(powmat(n, m1, mat)[0][1]).mod(m1));
			System.out.println(powmat(n, m2, mat)[0][0].add(powmat(n, m2, mat)[0][1]).mod(m2));
		}
	}
	

	// long
	// a [n,v] * b [v,m] => c[n,m]
	static BigInteger[][] mulmat(BigInteger[][] a, BigInteger[][] b, BigInteger mod) {
		assert(a[0].length == b.length);
		
		final int n = a.length;
		final int v = b.length;
		final int m = b[0].length;
		
		BigInteger[][] res = new BigInteger[n][m];
		for (BigInteger[] r : res) Arrays.fill(r, BigInteger.ZERO);
		for(int i = 0; i < n; i++)
			for(int k = 0; k < v; k++) {
				final BigInteger aa = a[i][k];
				for(int j = 0; j < m; j++) {
					res[i][j] = res[i][j].add(aa.multiply(b[k][j]));
				}
			}
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				res[i][j] = res[i][j].mod(mod);
		
		return res;
	}
	
	static BigInteger[][] powmat(long r, BigInteger mod, BigInteger[][] mat) {
		final int n = mat.length;
		BigInteger[][] x = new BigInteger[n][n];
		for (BigInteger[] y : x) Arrays.fill(y, BigInteger.ZERO);
		for(int i = 0; i < n; i++) {
			x[i][i] = BigInteger.ONE;
		}
		
		for(;r > 0; r >>>= 1) {
			if((r&1) == 1) {
				x = mulmat(x, mat, mod);
			}
			mat = mulmat(mat, mat, mod);
		}

		return x;
	}
	
	
	// for debug
	static void dump(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}
}
0