結果
問題 | No.492 IOI数列 |
ユーザー |
![]() |
提出日時 | 2017-03-10 23:37:47 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 162 ms / 1,000 ms |
コード長 | 2,049 bytes |
コンパイル時間 | 3,905 ms |
コンパイル使用メモリ | 79,608 KB |
実行使用メモリ | 54,560 KB |
最終ジャッジ日時 | 2024-06-24 08:58:08 |
合計ジャッジ時間 | 7,985 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
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 debugstatic void dump(Object... o) {System.err.println(Arrays.deepToString(o));}}