結果
問題 | No.2929 Miracle Branch |
ユーザー | detteiuu |
提出日時 | 2024-10-12 16:44:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,727 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 85,648 KB |
最終ジャッジ日時 | 2024-10-12 16:45:01 |
合計ジャッジ時間 | 8,911 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,400 KB |
testcase_01 | AC | 33 ms
52,680 KB |
testcase_02 | AC | 33 ms
52,948 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 | AC | 59 ms
70,324 KB |
testcase_19 | AC | 54 ms
71,756 KB |
testcase_20 | AC | 54 ms
73,704 KB |
testcase_21 | AC | 56 ms
76,556 KB |
testcase_22 | WA | - |
testcase_23 | AC | 59 ms
76,360 KB |
testcase_24 | AC | 75 ms
78,788 KB |
testcase_25 | WA | - |
testcase_26 | AC | 58 ms
63,872 KB |
testcase_27 | AC | 48 ms
65,920 KB |
testcase_28 | AC | 32 ms
52,352 KB |
testcase_29 | AC | 31 ms
52,736 KB |
testcase_30 | AC | 34 ms
52,992 KB |
testcase_31 | AC | 33 ms
52,736 KB |
testcase_32 | AC | 33 ms
52,736 KB |
testcase_33 | AC | 34 ms
52,992 KB |
testcase_34 | AC | 127 ms
85,236 KB |
testcase_35 | AC | 123 ms
85,556 KB |
testcase_36 | AC | 33 ms
52,992 KB |
testcase_37 | AC | 131 ms
85,632 KB |
testcase_38 | AC | 155 ms
85,308 KB |
testcase_39 | AC | 136 ms
85,376 KB |
testcase_40 | AC | 136 ms
85,648 KB |
testcase_41 | AC | 132 ms
85,632 KB |
testcase_42 | AC | 131 ms
85,248 KB |
testcase_43 | AC | 118 ms
84,992 KB |
testcase_44 | AC | 119 ms
85,504 KB |
testcase_45 | AC | 32 ms
52,864 KB |
ソースコード
X = int(input()) 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.append((p, s)) if n > 1: # n>1であればnは素数なので出力に追加 res.append((n, 1)) return res def divisor(n): ans = [1] pf = factorize(n) for p, c in pf: L = len(ans) for i in range(L): v = 1 for _ in range(c): v *= p ans.append(ans[i]*v) return sorted(ans) if X == 4: print(5) for i in range(2, 6): print(1, i) print("b", *(["g"]*4)) exit() F = factorize(X) if X == 1: F = [(1, 1)] cnt = 0 brown = 0 for n, c in F: cnt += n*c+c brown += c if cnt > 10**5*2: exit(print(-1)) print(cnt) b = 1 g = brown+1 for i, (n, c) in enumerate(F): for _ in range(c): for _ in range(n): print(b, g) g += 1 b += 1 for i in range(brown-1): print(i+1, i+2) print(*(["b"]*brown), *(["g"]*(cnt-brown)))