結果

問題 No.1200 お菓子配り-3
ユーザー mkawa2mkawa2
提出日時 2022-09-07 01:40:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 489 ms / 4,000 ms
コード長 1,757 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 78,124 KB
最終ジャッジ日時 2024-05-01 19:42:16
合計ジャッジ時間 5,199 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
61,952 KB
testcase_01 AC 46 ms
62,208 KB
testcase_02 AC 48 ms
62,848 KB
testcase_03 AC 49 ms
62,848 KB
testcase_04 AC 48 ms
62,776 KB
testcase_05 AC 48 ms
62,464 KB
testcase_06 AC 49 ms
62,464 KB
testcase_07 AC 54 ms
64,640 KB
testcase_08 AC 55 ms
64,384 KB
testcase_09 AC 53 ms
64,768 KB
testcase_10 AC 53 ms
64,512 KB
testcase_11 AC 53 ms
64,768 KB
testcase_12 AC 83 ms
77,184 KB
testcase_13 AC 85 ms
77,124 KB
testcase_14 AC 87 ms
77,056 KB
testcase_15 AC 87 ms
77,184 KB
testcase_16 AC 86 ms
76,800 KB
testcase_17 AC 131 ms
77,156 KB
testcase_18 AC 142 ms
77,568 KB
testcase_19 AC 89 ms
77,036 KB
testcase_20 AC 186 ms
77,824 KB
testcase_21 AC 190 ms
77,892 KB
testcase_22 AC 188 ms
77,952 KB
testcase_23 AC 186 ms
77,824 KB
testcase_24 AC 181 ms
78,020 KB
testcase_25 AC 181 ms
78,124 KB
testcase_26 AC 183 ms
77,696 KB
testcase_27 AC 46 ms
61,952 KB
testcase_28 AC 150 ms
77,480 KB
testcase_29 AC 489 ms
77,268 KB
testcase_30 AC 486 ms
77,268 KB
testcase_31 AC 47 ms
61,952 KB
testcase_32 AC 49 ms
61,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

a_max = 500000005
r = round(a_max**0.5)
while r**2 < a_max: r += 1
isp, pp = [1]*(r+1), []
for a in range(2, r+1):
    if isp[a]:
        pp.append(a)
        for b in range(a+a, r+1, a): isp[b] = 0

def factors(a):
    ff = [1]
    for p in pp:
        if a == 1: break
        c = 0
        if p**2 > a:
            p, a, c = a, 1, 1
        else:
            while a%p == 0: c, a = c+1, a//p
        if c == 0: continue
        w, nf = 1, []
        for _ in range(c):
            w *= p
            for f in ff: nf.append(f*w)
        ff += nf
    return ff

# ab+c=b+ac
# (a-1)b-(a-1)c=0
# (a-1)(b-c)=0

# ab+ c=x
#  b+ac=y
# (a-1)(b-c)=x-y

# ab+c=x
#  b-c=z
# (a+1)b=x+z
# b=(x+z)/(a+1)

def solve():
    x, y = LI()
    ans = 0
    if x == y:
        ans = len(factors(x))+x-2-(x & 1 == 0)
    else:
        if x < y: x, y = y, x
        for a1 in factors(x-y):
            a = a1+1
            z = (x-y)//a1
            if (x+z)%(a+1) == 0 and (x+z)//(a+1)-z > 0: ans += 1
    print(ans)

for _ in range(II()):
    solve()
0