結果
問題 | No.2365 Present of good number |
ユーザー | Mitarushi |
提出日時 | 2023-06-30 22:44:53 |
言語 | Nim (2.0.2) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,674 bytes |
コンパイル時間 | 6,327 ms |
コンパイル使用メモリ | 72,600 KB |
実行使用メモリ | 17,864 KB |
最終ジャッジ日時 | 2023-09-21 16:56:24 |
合計ジャッジ時間 | 9,071 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
17,864 KB |
testcase_01 | AC | 27 ms
13,264 KB |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
ソースコード
import strutils, sequtils, tables const factorTableSize = 100001 var factorTable: array[factorTableSize, seq[(int, int)]] for i in 2..<factorTableSize: if factorTable[i].len == 0: for j in 1..<factorTableSize div i: if factorTable[j].len > 0 and factorTable[j][^1][0] == i: factorTable[i * j].add((i, factorTable[j][^1][1] + 1)) else: factorTable[i * j].add((i, 1)) var n, k: int (n, k) = stdin.readLine.split.map(parseInt) const MOD = 1000000007 proc powMod(a, n: int): int = result = 1 var a = a n = n while n > 0: if n mod 2 == 1: result = (result * a) mod MOD a = (a * a) mod MOD n = n div 2 var factors = factorTable[n].toTable var count = 0 while count < k and not (factors.len == 1 and factors.keys.toSeq[0] <= 3 and (k - count) mod 2 == 0): var nextFactors = initTable[int, int]() for (p, power) in factors.pairs: for (q, power2) in factorTable[p + 1]: if not nextFactors.hasKey(q): nextFactors[q] = 0 nextFactors[q] = (nextFactors[q] + power * power2) mod (MOD - 1) count += 1 factors = nextFactors var remainK = k - count if remainK > 0: remainK = remainK div 2 var res = 1 x = 2 while remainK > 0: if remainK mod 2 == 1: res = (res * x) mod (MOD - 1) x = (x * x) mod (MOD - 1) remainK = remainK div 2 let key = factors.keys.toSeq[0] factors[key] = (factors[key] * res) mod (MOD - 1) var ans = 1 for (p, power) in factors.pairs: ans = (ans * powMod(p, power)) mod MOD echo ans