結果
問題 | No.2365 Present of good number |
ユーザー | kakel-san |
提出日時 | 2023-08-17 12:13:22 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 3,670 bytes |
コンパイル時間 | 1,060 ms |
コンパイル使用メモリ | 115,376 KB |
実行使用メモリ | 27,412 KB |
最終ジャッジ日時 | 2024-11-26 08:42:42 |
合計ジャッジ時間 | 3,567 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
25,496 KB |
testcase_01 | AC | 30 ms
25,224 KB |
testcase_02 | AC | 29 ms
27,396 KB |
testcase_03 | AC | 31 ms
25,500 KB |
testcase_04 | AC | 32 ms
25,488 KB |
testcase_05 | AC | 31 ms
27,284 KB |
testcase_06 | AC | 32 ms
25,500 KB |
testcase_07 | AC | 30 ms
25,396 KB |
testcase_08 | AC | 30 ms
25,220 KB |
testcase_09 | AC | 31 ms
25,376 KB |
testcase_10 | AC | 31 ms
25,356 KB |
testcase_11 | AC | 30 ms
25,132 KB |
testcase_12 | AC | 30 ms
25,476 KB |
testcase_13 | AC | 30 ms
27,396 KB |
testcase_14 | AC | 30 ms
25,240 KB |
testcase_15 | AC | 31 ms
25,364 KB |
testcase_16 | AC | 29 ms
25,360 KB |
testcase_17 | AC | 29 ms
25,236 KB |
testcase_18 | AC | 31 ms
27,408 KB |
testcase_19 | AC | 31 ms
25,356 KB |
testcase_20 | AC | 31 ms
27,280 KB |
testcase_21 | AC | 29 ms
27,392 KB |
testcase_22 | AC | 29 ms
25,264 KB |
testcase_23 | AC | 30 ms
27,392 KB |
testcase_24 | AC | 30 ms
25,116 KB |
testcase_25 | AC | 30 ms
25,216 KB |
testcase_26 | AC | 29 ms
25,260 KB |
testcase_27 | AC | 30 ms
25,480 KB |
testcase_28 | AC | 31 ms
27,408 KB |
testcase_29 | AC | 30 ms
27,412 KB |
testcase_30 | AC | 31 ms
25,240 KB |
testcase_31 | AC | 31 ms
27,412 KB |
testcase_32 | AC | 30 ms
25,256 KB |
testcase_33 | AC | 30 ms
23,220 KB |
testcase_34 | AC | 30 ms
25,372 KB |
testcase_35 | AC | 30 ms
25,356 KB |
testcase_36 | AC | 29 ms
25,396 KB |
testcase_37 | AC | 30 ms
27,412 KB |
testcase_38 | AC | 29 ms
23,088 KB |
testcase_39 | AC | 29 ms
25,392 KB |
testcase_40 | AC | 30 ms
25,476 KB |
コンパイルメッセージ
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]); WriteLine(Good(n, k)); } static long Good(long n, long k) { 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] += kv.Value * nkv.Value; else np[nkv.Key] = kv.Value * 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; return ans2; } } 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)); return 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; } } }