結果

問題 No.2929 Miracle Branch
ユーザー ntuda
提出日時 2024-10-14 15:35:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 94,208 KB
最終ジャッジ日時 2024-10-14 15:35:50
合計ジャッジ時間 11,742 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f <= INF and f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

X = int(input())
INF = 2 * 10 ** 5
D = prime_factorize(X)[::-1]
if D == []:
    D = [1]
D2 = []
while len(D) >= 2 and D[-2:] == [2,2]:
    D.pop()
    D.pop()
    D2.append(4)
D += D2
ans = len(D) + sum(D)
if ans > INF:
    print(-1)
    exit()
b = len(D)
UV = []
tmp = b
for i in range(b):
    if i > 0:
        UV.append((i - 1, i))
    for d in range(D[i]):
        UV.append((i, tmp))
        tmp += 1
else:
    print(ans)
for u, v in UV:
    print(u + 1, v + 1)
C = ["b"] * b + ["g"] * (ans - b)
print(*C)
0