結果

問題 No.376 立方体のN等分 (2)
ユーザー ebicochineal
提出日時 2016-06-18 01:12:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 511 ms / 5,000 ms
コード長 939 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 153,932 KB
最終ジャッジ日時 2024-11-06 23:30:41
合計ジャッジ時間 5,562 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n):
    l = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            l += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : l += [n]
    return l

def e(a, b, c, i):
    global tmin
    t = tuple(sorted([a,b,c]))
    if t in m:
        return
    else:
        m.add(t)
    s = sum((a, b, c))
    if i < 0:
        if s < tmin : tmin = s
        return
    if s > tmin : return
    j = i - 1
    e(a*p[i], b, c, j)
    e(a, b*p[i], c, j)
    e(a, b, c*p[i], j)

m = set()
tmin = 0
N = int(input())
p = f(N)
if len(p) > 3:
    tmin = N - 1
    b = 1
    while b:
        b = 0
        l = []
        for i in set(p):
            if p.count(i) > 3:
                l += [i]*(p.count(i)-2) + [i*i]
                b = 1
            else:
                l += [i]*(p.count(i))
        p = l
    e(1, 1, 1, len(p)-1)
    print(tmin-3, N-1)
else:
    print(sum(p)-len(p), N-1)
0