結果
問題 |
No.2954 Calculation of Exponentiation
|
ユーザー |
![]() |
提出日時 | 2025-01-11 13:19:07 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,321 bytes |
コンパイル時間 | 556 ms |
コンパイル使用メモリ | 81,904 KB |
実行使用メモリ | 80,544 KB |
最終ジャッジ日時 | 2025-01-11 13:19:14 |
合計ジャッジ時間 | 5,587 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 4 |
ソースコード
#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) #2. コーナーケースを処理 if B == 0: return True #3. A = C / 10000 = P / Q の形に変換。Q != 1 ならFalse gcd = lambda x, y: gcd(y, x % y) if y else abs(x) P, Q = C // gcd(C, 10000), 10000 // gcd(C, 10000) if Q != 1: return False #4. Pを素因数分解 F = [] x = P 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)) if x > 1: F.append((x, 1)) #5. P = Π(Pi ** Ei) に対して、Ei * (D / 10000) がすべて非負整数ならTrue for Pi, Ei in F: if Ei * D % 10000 == 0 and Ei * D // 10000 >= 0: continue else: return False else: return True print( 'Yes' if solve(A, B) else 'No' )