結果

問題 No.2929 Miracle Branch
ユーザー vwxyz
提出日時 2024-10-12 15:06:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 94,976 KB
最終ジャッジ日時 2024-10-12 15:06:48
合計ジャッジ時間 10,670 ms
ジャッジサーバーID
(参考情報)
judge5 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

X=int(input())
fact=defaultdict(int)
if X==1:
    print(2)
    print(1,2)
    print("b","g")
    exit()
for p in range(2,2*10**5):
    while X%p==0:
        X//=p
        fact[p]+=1
if X>1:
    fact[X]+=1
if 2 in fact:
    c=fact[2]
    fact[4]=c//2
    fact[2]=c%2
s=0
le=0
for p,e in fact.items():
    s+=(p+1)*e
    le+=e
if s>2*10**5:
    print(-1)
    exit()
ans_lst=[]
for i in range(le-1):
    ans_lst.append((i,i+1))
cur0=0
cur1=le
for p,e in fact.items():
    for i in range(e):
        for j in range(p):
            ans_lst.append((cur0,cur1))
            cur1+=1
        cur0+=1
assert len(ans_lst)==s-1
print(s)
for i,j in ans_lst:
    print(i+1,j+1)
print(*["b"]*le+["g"]*(s-le))
0