結果

問題 No.1556 Power Equality
ユーザー moharan627
提出日時 2021-06-25 21:30:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,323 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-06-25 09:45:43
合計ジャッジ時間 985 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(10 ** 6)
INF = float('inf')
#10**20に変えるのもあり
MOD = 10**9 + 7
MOD2 = 998244353
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a
    A,B = MI()
    import collections
    APri = prime_factorize(A)
    BPri = prime_factorize(B)
    from collections import defaultdict
    ANum = defaultdict(lambda: 0)
    for a in APri:
        ANum[a]+=1
    BNum = defaultdict(lambda: 0)
    for b in BPri:
        BNum[b]+=1
    #print(ANum)
    #print(BNum)
    flag = True
    for a in ANum.keys():
        if(ANum[a]*B != BNum[a]*A):
            flag = False
    for b in BNum.keys():
        if (ANum[b] * B != BNum[b] * A):
            flag = False
    if(flag):
        print("Yes")
    else:
        print("No")
    return
solve()
0