結果
問題 | No.2929 Miracle Branch |
ユーザー |
![]() |
提出日時 | 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 copyfrom itertools import combinations, permutations, product, accumulate, groupby, chain# from more_itertools import distinct_permutationsfrom heapq import heapify, heappop, heappushimport mathimport bisect# from pprint import pprintfrom random import randint, shuffle, randrange# from sortedcontainers import SortedSet, SortedList, SortedDictimport sys# sys.setrecursionlimit(2000000)input = lambda: sys.stdin.readline().rstrip('\n')inf = float('inf')mod1 = 10**9+7mod2 = 998244353def ceil_div(x, y): return -(-x//y)################################################## https://github.com/shakayami/ACL-for-python/blob/master/prime_fact.pyfrom math import gcdimport randomfrom collections import Counterdef is_probable_prime(n):if n==2:return Trueif n==1 or n&1==0:return Falsed=(n-1)>>1while d&1==0:d>>=1for k in range(100):a=random.randint(1,n-1)t=dy=pow(a, t, n)while t!=n-1 and y!=1 and y!=n-1:y=(y*y)%nt<<=1if y!=n-1 and t&1==0:return Falsereturn Truedef _solve(N):if is_probable_prime(N):return Nwhile(True):x=random.randrange(N)c=random.randrange(N)y=(x*x+c)%Nd=1while(d==1):d=gcd(x-y,N)x=(x*x+c)%Ny=(y*y+c)%Ny=(y*y+c)%Nif 1<d<N:return _solve(d)def prime_fact(N):res=Counter()p=2while(p<=10**4 and N>1):if N%p==0:while(N%p==0):res[p]+=1N//=pp+=1while(N>1):p=_solve(N)while(N%p)==0:res[p]+=1N//=preturn resX = int(input())if X == 1:print(2)print(1, 2)print("b", "g")exit()pf = prime_fact(X)n = 0ans_e = []ans_c = []for p, e in pf.items():if p == 2:if e%2 == 1:pn = nn += (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 = 4e //= 2pn = nn += (p+1)*eif 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+1print(n)for u, v in ans_e:print(u, v)print(*ans_c)