結果
問題 | No.492 IOI数列 |
ユーザー | zimpha |
提出日時 | 2017-03-29 21:59:06 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,240 bytes |
コンパイル時間 | 2,024 ms |
コンパイル使用メモリ | 78,188 KB |
実行使用メモリ | 50,668 KB |
最終ジャッジ日時 | 2024-07-06 15:10:57 |
合計ジャッジ時間 | 3,691 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
50,248 KB |
testcase_01 | AC | 52 ms
50,484 KB |
testcase_02 | AC | 51 ms
50,416 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 50 ms
50,444 KB |
testcase_09 | WA | - |
testcase_10 | AC | 49 ms
50,280 KB |
testcase_11 | AC | 49 ms
50,264 KB |
testcase_12 | AC | 49 ms
50,488 KB |
testcase_13 | AC | 49 ms
50,552 KB |
testcase_14 | AC | 50 ms
50,440 KB |
testcase_15 | AC | 49 ms
50,504 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 48 ms
50,540 KB |
testcase_21 | WA | - |
ソースコード
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("10101010101010101"))); } 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()); } } }