結果
問題 | No.2929 Miracle Branch |
ユーザー | Yakumo221 |
提出日時 | 2024-10-12 15:54:33 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,491 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 81,844 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-10-12 15:54:44 |
合計ジャッジ時間 | 10,757 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,608 KB |
testcase_01 | WA | - |
testcase_02 | AC | 42 ms
52,608 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 41 ms
52,608 KB |
testcase_29 | AC | 41 ms
52,224 KB |
testcase_30 | AC | 47 ms
52,224 KB |
testcase_31 | AC | 41 ms
52,864 KB |
testcase_32 | AC | 41 ms
52,608 KB |
testcase_33 | AC | 42 ms
52,864 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 41 ms
52,992 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | AC | 39 ms
52,864 KB |
ソースコード
# library from https://qiita.com/t_fuki/items/7cd50de54d3c5d063b4a def gcd(a, b): while a: a, b = b%a, a return b def is_prime(n): if n == 2: return 1 if n == 1 or n%2 == 0: return 0 m = n - 1 lsb = m & -m s = lsb.bit_length()-1 d = m // lsb test_numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] for a in test_numbers: if a == n: continue x = pow(a,d,n) r = 0 if x == 1: continue while x != m: x = pow(x,2,n) r += 1 if x == 1 or r == s: return 0 return 1 def find_prime_factor(n): if n%2 == 0: return 2 m = int(n**0.125)+1 for c in range(1,n): f = lambda a: (pow(a,2,n)+c)%n y = 0 g = q = r = 1 k = 0 while g == 1: x = y while k < 3*r//4: y = f(y) k += 1 while k < r and g == 1: ys = y for _ in range(min(m, r-k)): y = f(y) q = q*abs(x-y)%n g = gcd(q,n) k += m k = r r *= 2 if g == n: g = 1 y = ys while g == 1: y = f(y) g = gcd(abs(x-y),n) if g == n: continue if is_prime(g): return g elif is_prime(n//g): return n//g else: return find_prime_factor(g) def factorize(n): res = {} while not is_prime(n) and n > 1: # nが合成数である間nの素因数の探索を繰り返す p = find_prime_factor(n) s = 0 while n%p == 0: # nが素因数pで割れる間割り続け、出力に追加 n //= p s += 1 res[p] = s if n > 1: # n>1であればnは素数なので出力に追加 res[n] = 1 return res x = int(input()) if x == 1: print(2) print(1,2) print("b","g") exit() fac = factorize(x) gre = [] for key, val in fac.items(): if key == 2: gre.extend([4] * (val//2) + [2] * (val % 2)) else: gre.extend([key] * val) bro = len(gre) tot = bro + sum(gre) if tot > 200000: print(-1) exit() print(tot) for i in range(1, bro): print(i, i+1) cnt = bro+1 for i in range(bro): for j in range(gre[i]): print(i+1, cnt) cnt += 1