結果
| 問題 | No.2929 Miracle Branch | 
| コンテスト | |
| ユーザー |  prin_kemkem | 
| 提出日時 | 2024-10-12 16:52:22 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 174 ms / 2,000 ms | 
| コード長 | 2,773 bytes | 
| コンパイル時間 | 153 ms | 
| コンパイル使用メモリ | 82,520 KB | 
| 実行使用メモリ | 100,824 KB | 
| 最終ジャッジ日時 | 2024-10-12 16:52:35 | 
| 合計ジャッジ時間 | 10,049 ms | 
| ジャッジサーバーID (参考情報) | judge / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
ソースコード
from collections import defaultdict, deque, Counter
# from functools import cache
# import copy
from itertools import combinations, permutations, product, accumulate, groupby, chain
# from more_itertools import distinct_permutations
from heapq import heapify, heappop, heappush
import math
import bisect
# from pprint import pprint
from random import randint, shuffle, randrange
# from sortedcontainers import SortedSet, SortedList, SortedDict
import sys
# sys.setrecursionlimit(2000000)
input = lambda: sys.stdin.readline().rstrip('\n')
inf = float('inf')
mod1 = 10**9+7
mod2 = 998244353
def ceil_div(x, y): return -(-x//y)
#################################################   
# https://github.com/shakayami/ACL-for-python/blob/master/prime_fact.py
from math import gcd
import random
from collections import Counter
def is_probable_prime(n):
    if n==2:
        return True
    if n==1 or n&1==0:
        return False
    d=(n-1)>>1
    while d&1==0:
        d>>=1
    for k in range(100):
        a=random.randint(1,n-1)
        t=d
        y=pow(a, t, n)
        while t!=n-1 and y!=1 and y!=n-1:
            y=(y*y)%n
            t<<=1
        if y!=n-1 and t&1==0:
            return False
    return True
def _solve(N):
    if is_probable_prime(N):
        return N
    while(True):
        x=random.randrange(N)
        c=random.randrange(N)
        y=(x*x+c)%N
        d=1
        while(d==1):
            d=gcd(x-y,N)
            x=(x*x+c)%N
            y=(y*y+c)%N
            y=(y*y+c)%N
        if 1<d<N:
            return _solve(d)
def prime_fact(N):
    res=Counter()
    p=2
    while(p<=10**4 and N>1):
        if N%p==0:
            while(N%p==0):
                res[p]+=1
                N//=p
        p+=1
    while(N>1):
        p=_solve(N)
        while(N%p)==0:
            res[p]+=1
            N//=p
    return res
X = int(input())
if X == 1:
    print(2)
    print(1, 2)
    print("b", "g")
    exit()
pf = prime_fact(X)
n = 0
ans_e = []
ans_c = []
for p, e in pf.items():
    if p == 2:
        if e%2 == 1:
            pn = n
            n += (p+1)
            if n > 2*10**5:
                print(-1)
                exit()
            ans_c.extend(["g"]*2)
            ans_c.append("b")
            if ans_e:
                ans_e.append((pn, pn+p+1))
            for i in range(pn+1, pn+p+1):
                ans_e.append((i, pn+p+1))
        p = 4
        e //= 2
    pn = n
    n += (p+1)*e
    if n > 2*10**5:
        print(-1)
        exit()
    for _ in range(e):
        ans_c.extend(["g"]*p)
        ans_c.append("b")
        if ans_e:
            ans_e.append((pn, pn+p+1))
        for i in range(pn+1, pn+p+1):
            ans_e.append((i, pn+p+1))
        pn += p+1
print(n)
for u, v in ans_e:
    print(u, v)
print(*ans_c)
            
            
            
        