結果
問題 | No.1200 お菓子配り-3 |
ユーザー | neterukun |
提出日時 | 2020-08-28 22:39:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,030 bytes |
コンパイル時間 | 416 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 80,208 KB |
最終ジャッジ日時 | 2024-11-14 16:08:24 |
合計ジャッジ時間 | 6,461 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,532 KB |
testcase_01 | AC | 38 ms
53,212 KB |
testcase_02 | AC | 39 ms
53,148 KB |
testcase_03 | AC | 40 ms
53,704 KB |
testcase_04 | AC | 40 ms
54,304 KB |
testcase_05 | AC | 39 ms
53,752 KB |
testcase_06 | AC | 43 ms
59,248 KB |
testcase_07 | AC | 63 ms
67,968 KB |
testcase_08 | AC | 63 ms
68,548 KB |
testcase_09 | AC | 61 ms
67,780 KB |
testcase_10 | AC | 67 ms
71,548 KB |
testcase_11 | AC | 64 ms
68,448 KB |
testcase_12 | AC | 164 ms
78,452 KB |
testcase_13 | AC | 160 ms
78,192 KB |
testcase_14 | AC | 152 ms
78,344 KB |
testcase_15 | AC | 155 ms
77,980 KB |
testcase_16 | AC | 154 ms
78,072 KB |
testcase_17 | AC | 237 ms
78,708 KB |
testcase_18 | AC | 275 ms
79,328 KB |
testcase_19 | AC | 161 ms
78,492 KB |
testcase_20 | AC | 328 ms
79,952 KB |
testcase_21 | AC | 321 ms
80,208 KB |
testcase_22 | AC | 325 ms
79,616 KB |
testcase_23 | AC | 324 ms
79,496 KB |
testcase_24 | AC | 301 ms
79,404 KB |
testcase_25 | AC | 310 ms
79,372 KB |
testcase_26 | AC | 316 ms
79,376 KB |
testcase_27 | AC | 38 ms
53,436 KB |
testcase_28 | AC | 279 ms
78,708 KB |
testcase_29 | AC | 120 ms
76,896 KB |
testcase_30 | AC | 115 ms
77,088 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
ソースコード
import sys input = sys.stdin.buffer.readline def gcd(a, b): while b: a, b = b, a % b return a def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = [2] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n): m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i*i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i % 2 if i == 101 and n >= 2 ** 20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret def make_divisors(n): def solve(li, ind, val): if ind == len(li): res.append(val) return for v in li[ind]: solve(li, ind + 1, val * v) factors = primeFactor(n) li = [] for v in factors: tmp = [1] val = v for _ in range(factors[val]): tmp.append(val) val *= v li.append(tmp) res = [] solve(li, 0, 1) return res s = int(input()) memo = {} for _ in range(s): x, y = map(int, input().split()) if x < y: x, y = y, x sum_ = x + y diff = x - y cnt = 0 if diff == 0: cnt += x - 1 # b * (a + 1) = x cnt += (len(make_divisors(x)) - 1) print(cnt) continue for div in make_divisors(diff): a = div + 1 # b + c = sum_ // (a + 1) # b - c = diff // (a - 1) if sum_ % (a + 1) != 0: continue t1, t2 = sum_ // (a + 1), diff // (a - 1) if (t1 + t2) % 2 == 1: continue b, c = (t1 + t2) // 2, (t1 - t2) // 2 if b > 0 and c > 0: cnt += 1 print(cnt)