結果

問題 No.1200 お菓子配り-3
ユーザー brthyyjp
提出日時 2020-08-28 22:58:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,921 ms / 4,000 ms
コード長 1,335 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 77,588 KB
最終ジャッジ日時 2024-11-20 22:47:41
合計ジャッジ時間 21,161 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort(reverse=True)
    return divisors

def main():
    s = int(input())



    for _ in range(s):
        x, y = map(int, input().split())
        t = x-y
        if t == 0:
            ans = x-1
            D = make_divisors(x)
            if x%2 == 0:
                for d in D:
                    if d >= 3:
                        ans += 1
            else:
                for d in D:
                    if d >= 2:
                        ans += 1
            print(ans)
        elif t > 0:
            D = make_divisors(t)
            ans = 0
            for d in D:
                a = d+1
                if (a*y-x)>0 and (a*y-x)%(a**2-1) == 0 and (a*x-y)>0 and (a*x-y)%(a**2-1) == 0:
                     ans += 1
            print(ans)
        else:
            t = (-1)*t
            D = make_divisors(t)
            ans = 0
            for d in D:
                a = d+1
                if (a*y-x)>0 and (a*y-x)%(a**2-1) == 0 and (a*x-y)>0 and (a*x-y)%(a**2-1) == 0:
                     ans += 1
            print(ans)

if __name__ == '__main__':
    main()
0