結果

問題 No.2954 Calculation of Exponentiation
ユーザー navel_tos
提出日時 2025-01-11 13:27:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 80,768 KB
最終ジャッジ日時 2025-01-11 13:27:38
合計ジャッジ時間 4,633 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#yukicoder2954 Calculation of Exponentiation

#入力受取
A, B = input().split()

from decimal import Decimal, getcontext
def brute(A, B):
    getcontext().prec = 3000
    C = pow( Decimal(A), Decimal(B) )
    return round(C, 2000) == round(C)  #ノックダウンあり
    
def solve(A, B):
    #1. A, Bを A / 10000 の形に変更
    convert = lambda S: int( S.replace( '.', '' ) )
    C, D = convert(A), convert(B)

    #3. A = C / 10000 = P / Q の形に変換
    gcd = lambda x, y: gcd(y, x % y) if y else abs(x)
    P, Q = C // gcd(C, 10000), 10000 // gcd(C, 10000)

    #4. P, Qを素因数分解し、Qの次数は正負反転する
    def factorial(x):
        F = []
        for p in range(2, x + 1):
            if p ** 2 > x:
                break
            if ( x % p == 0 ) and ( c := 0 ) == 0:
                while x % p == 0 < ( c := c + 1 ):
                    x //= p
                F.append((x, c))
        return F if x == 1 else F + [(x, 1)]
    F = factorial(P) + [(Pi, - Ei) for Pi, Ei in factorial(Q)]

    #5. P / Q = Π(Pi ** Ei) に対し、Ei * (D / 10000) がすべて非負整数ならTrue
    return all(Ei * D % 10000 == 0 <= Ei * D for Pi, Ei in F)


print( 'Yes' if solve(A, B) else 'No' )
0