結果

問題 No.847 Divisors of Power
ユーザー 6soukiti296soukiti29
提出日時 2019-07-07 09:49:21
言語 Nim
(2.0.2)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,094 bytes
コンパイル時間 3,416 ms
コンパイル使用メモリ 69,476 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 23:30:36
合計ジャッジ時間 4,684 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 25 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 29 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,strutils,algorithm
type
    prime = tuple[i : int64, n : int64]
var
    N, K, M : int64
    P = newSeq[int64](0)
(N, K, M) = stdin.readline.split.map(parseBiggestInt)

proc `^`(a: int64, b : int64) : int64 =
    if b == 0:
        return 1
    elif b == 1:
        return a
    elif b mod 2 == 0:
        return (a * a) ^ (b div 2)
    else:
        return a * (a ^ (b - 1))


var
    i : int64 = 2
    ps = newSeq[prime](0)
while i * i <= N:
    while N mod i == 0:
        N = N div i
        P.add(i)
    i += 1
if N > 1:
    P.add(N)
P.sort(cmp)
for j, p in P:
    if j == 0:
        ps.add((p, 1.int64))
    elif p == P[j - 1]:
        ps[^1].n += 1
    else:
        ps.add((p, 1.int64))
var
    cnt = newSeqWith(ps.len(),0.int64)
    ans = 0
for i, p in ps:
    ps[i].n *= K
proc dfs(k : int) =
    var z : int64 = 1
    for i,c in cnt:
        z *= ps[i].i ^ c
        if z > M:
            return
    ans += 1
    for i in k..<cnt.len:
        if cnt[i] == ps[i].n:
            continue
        cnt[i] += 1
        dfs(i)
        cnt[i] -= 1
    return
dfs(0)
echo ans
0