結果
問題 | No.2365 Present of good number |
ユーザー | kakel-san |
提出日時 | 2023-08-17 12:06:43 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,597 bytes |
コンパイル時間 | 1,262 ms |
コンパイル使用メモリ | 108,416 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-05-04 18:49:17 |
合計ジャッジ時間 | 3,850 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
19,328 KB |
testcase_01 | AC | 31 ms
19,072 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 30 ms
19,200 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 31 ms
19,200 KB |
testcase_17 | AC | 31 ms
19,200 KB |
testcase_18 | AC | 31 ms
19,072 KB |
testcase_19 | AC | 31 ms
18,944 KB |
testcase_20 | AC | 31 ms
18,944 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 31 ms
19,328 KB |
testcase_32 | AC | 31 ms
19,072 KB |
testcase_33 | AC | 31 ms
19,072 KB |
testcase_34 | AC | 32 ms
19,072 KB |
testcase_35 | AC | 31 ms
19,200 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k) = (c[0], c[1]); var mod = 1_000_000_007; var p = PDiv(n); while (p.Count != (p.ContainsKey(2) ? 1 : 0) + (p.ContainsKey(3) ? 1 : 0)) { var np = new Dictionary<long, long>(); foreach (var kv in p) { var nkey = PDiv(kv.Key + 1); foreach (var nkv in nkey) { if (np.ContainsKey(nkv.Key)) np[nkv.Key] += nkv.Value; else np[nkv.Key] = nkv.Value; } } --k; p = np; if (k == 0) { var ans2 = 1L; foreach (var kv in p) for (var i = 0; i < kv.Value; ++i) ans2 = ans2 * kv.Key % mod; WriteLine(ans2); return; } } var m = new Matrix(mod - 1); var a = new long[][] { new long[] { p.ContainsKey(2) ? p[2] : 0, p.ContainsKey(3) ? p[3] : 0 }}; var x = new long[][] { new long[] { 0, 1 }, new long[] { 2, 0 }}; var b = m.Mul(a, m.Pow(x, k)); WriteLine(Exp(2, b[0][0], mod) * Exp(3, b[0][1], mod) % mod); } static long Exp(long n, long k, int mod) { if (k == 0) return 1; if (k == 1) return n % mod; var half = Exp(n, k / 2, mod); var result = (half * half) % mod; return ((k % 2) == 0) ? result : ((result * n) % mod); } static Dictionary<long, long> PDiv(long n) { var dic = new Dictionary<long, long>(); var tmp = n; while (tmp % 2 == 0) { tmp /= 2; if (dic.ContainsKey(2)) ++dic[2]; else dic.Add(2, 1); } for (var p = 3L; p * p <= n; p += 2) { while (tmp % p == 0) { tmp /= p; if (dic.ContainsKey(p)) ++dic[p]; else dic.Add(p, 1); } if (tmp == 1) break; } if (tmp > 1) dic.Add(tmp, 1); return dic; } class Matrix { int mod; // 行列の累乗 public Matrix(int _mod = 1_000_000_007) { mod = _mod; } public long[][] Pow(long[][] m, long k) { var multi = m; var r = new long[m.Length][]; for (var i = 0; i < m.Length; ++i) { r[i] = new long[m.Length]; r[i][i] = 1; } while (k > 0) { if ((k & 1) == 1) r = Mul(r, multi); multi = Mul(multi, multi); k >>= 1; } return r; } // 行列の積 public long[][] Mul(long[][] x, long[][] y) { var r = new long[x.Length][]; for (var i = 0; i < x.Length; ++i) r[i] = new long[y[0].Length]; for (var i = 0; i < x.Length; ++i) for (var k = 0; k < x[0].Length; ++k) { for (var j = 0; j < y[0].Length; ++j) r[i][j] = (r[i][j] + x[i][k] * y[k][j]) % mod; } return r; } } }