結果

問題 No.1200 お菓子配り-3
ユーザー chineristAC
提出日時 2020-08-28 21:42:59
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 76,820 KB
最終ジャッジ日時 2024-11-14 14:28:43
合計ジャッジ時間 42,065 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisors(M):#Mの約数列 O(n^(0.5+e))
    import math
    d=[]
    i=1
    while math.sqrt(M)>=i:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    d.sort()
    return d

import sys

input= sys.stdin.readline

for _ in range(int(input())):
    x,y = map(int,input().split())
    div = divisors(x+y)
    count = 0
    for d in div:
        if x!=y:
            if d==1 or d==2:
                continue

            if (x+y)%d!=0 or (x-y)%(d-2)!=0:
                continue

            s = (x + y) // d
            t = (x - y) // (d-2)
            if (s + t) % 2 !=0:
                continue
            b = (s + t) // 2
            c = (s - t) // 2

            if b>0 and c>0:
                count += 1

        else:
            if d==1:
                continue
            if d==2:
                s = (x + y) // d
                count += s - 1
            else:
                if ((x+y) // d) %2 ==0:
                    count += 1

    print(count)
0