結果

問題 No.1224 I hate Sqrt Inequality
ユーザー ThetaTheta
提出日時 2022-11-02 18:43:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,648 ms / 2,000 ms
コード長 1,203 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 8,400 KB
最終ジャッジ日時 2023-09-24 07:11:31
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,368 KB
testcase_01 AC 17 ms
8,268 KB
testcase_02 AC 16 ms
8,376 KB
testcase_03 AC 17 ms
8,216 KB
testcase_04 AC 17 ms
8,396 KB
testcase_05 AC 16 ms
8,324 KB
testcase_06 AC 39 ms
8,352 KB
testcase_07 AC 17 ms
8,324 KB
testcase_08 AC 17 ms
8,216 KB
testcase_09 AC 17 ms
8,200 KB
testcase_10 AC 667 ms
8,324 KB
testcase_11 AC 1,648 ms
8,400 KB
testcase_12 AC 17 ms
8,200 KB
testcase_13 AC 16 ms
8,204 KB
testcase_14 AC 16 ms
8,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count


def gcd(*numbers: int) -> int:
    if len(numbers) == 1:
        return numbers[0]
    if len(numbers) == 2:
        a, b = numbers
        if a < b:
            a, b = b, a

        while True:

            if a % b == 0:
                return b
            a, b = b, a % b

    first_gcd = gcd(*numbers[:2])
    return gcd(first_gcd, *numbers[2:])


def calc_prime_factorize(num: int) -> dict[int, int]:
    if num < 2:
        raise ValueError

    divisors = {}
    for divisor in count(2):
        if divisor ** 2 > num:
            if num != 1:
                divisors[num] = 1
            break
        while num % divisor == 0 and num != 1:
            try:
                divisors[divisor] += 1
            except KeyError:
                divisors[divisor] = 1
            num //= divisor

    return divisors


def main():
    a, b = map(int, input().split())
    ab_gcd = gcd(a, b)
    a //= ab_gcd
    b //= ab_gcd

    if b == 1:
        print("No")
        return

    b_factor = calc_prime_factorize(b)
    if all(factor in (2, 5) for factor in b_factor.keys()):
        print("No")
    else:
        print("Yes")


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