結果
問題 | No.492 IOI数列 |
ユーザー | zimpha |
提出日時 | 2017-03-29 22:00:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 52 ms / 1,000 ms |
コード長 | 3,244 bytes |
コンパイル時間 | 2,429 ms |
コンパイル使用メモリ | 78,624 KB |
実行使用メモリ | 50,620 KB |
最終ジャッジ日時 | 2024-07-06 15:11:01 |
合計ジャッジ時間 | 3,670 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
50,364 KB |
testcase_01 | AC | 51 ms
50,196 KB |
testcase_02 | AC | 51 ms
50,620 KB |
testcase_03 | AC | 52 ms
50,192 KB |
testcase_04 | AC | 49 ms
50,588 KB |
testcase_05 | AC | 49 ms
50,608 KB |
testcase_06 | AC | 51 ms
50,564 KB |
testcase_07 | AC | 51 ms
50,532 KB |
testcase_08 | AC | 51 ms
50,592 KB |
testcase_09 | AC | 50 ms
50,340 KB |
testcase_10 | AC | 47 ms
50,364 KB |
testcase_11 | AC | 47 ms
50,372 KB |
testcase_12 | AC | 48 ms
50,496 KB |
testcase_13 | AC | 49 ms
50,304 KB |
testcase_14 | AC | 47 ms
50,440 KB |
testcase_15 | AC | 47 ms
50,512 KB |
testcase_16 | AC | 48 ms
50,460 KB |
testcase_17 | AC | 47 ms
50,264 KB |
testcase_18 | AC | 47 ms
50,472 KB |
testcase_19 | AC | 48 ms
50,340 KB |
testcase_20 | AC | 48 ms
50,612 KB |
testcase_21 | AC | 48 ms
50,460 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.math.BigInteger; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Chiaki.Hoshinomori */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task492 solver = new Task492(); solver.solve(1, in, out); out.close(); } static class Task492 { public void solve(int testNumber, InputReader in, PrintWriter out) { long n = in.nextLong(); out.println(solve(n - 1, BigInteger.valueOf(1000000007))); out.println(solve(n - 1, new BigInteger("101010101010101010101"))); } BigInteger solve(long n, BigInteger mod) { BigInteger[] ret = new BigInteger[]{BigInteger.ONE, BigInteger.ONE}; BigInteger[][] A = new BigInteger[2][]; A[0] = new BigInteger[]{BigInteger.valueOf(100), BigInteger.ONE}; A[1] = new BigInteger[]{BigInteger.ZERO, BigInteger.ONE}; for (; n > 0; n >>= 1) { if (n % 2 == 1) { BigInteger t0 = A[0][0].multiply(ret[0]).add(A[0][1].multiply(ret[1])).mod(mod); BigInteger t1 = A[1][0].multiply(ret[0]).add(A[1][1].multiply(ret[1])).mod(mod); ret[0] = t0; ret[1] = t1; } A = mul(A, A, mod); } return ret[0]; } private BigInteger[][] mul(BigInteger[][] a, BigInteger[][] b, BigInteger mod) { BigInteger[][] c = new BigInteger[2][]; for (int i = 0; i < 2; i++) { c[i] = new BigInteger[2]; } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { c[i][j] = BigInteger.ZERO; for (int k = 0; k < 2; k++) { c[i][j] = c[i][j].add(a[i][k].multiply(b[k][j])); } c[i][j] = c[i][j].mod(mod); } } return c; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } } }