結果

問題 No.2954 Calculation of Exponentiation
ユーザー dp_ijk
提出日時 2024-11-08 22:17:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 673 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 88,832 KB
最終ジャッジ日時 2024-11-08 22:18:14
合計ジャッジ時間 6,453 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

def factors(X: int):
   assert X >= 1
   F: list[tuple[int, int]] = []
   d = 2
   while d*d <= X:
      e = 0
      while X%d == 0:
         e += 1
         X //= d
      if e > 0:
         F.append((d, e))
      d += 1
   if X > 1:
      F.append((X, 1))
   return F

from fractions import Fraction

A, B = map(Fraction, input().split())


def solve(A, B):
   p, q = A.as_integer_ratio()
   if q != 1:
      return False
   x, y = B.as_integer_ratio()
   for _, e in factors(A):
      if Fraction(e*p, y).as_integer_ratio()[1] != 1:
         return False
   return True


ans = solve(A, B)
if ans == True:
   print("Yes")
elif ans == False:
   print("No")
else:
   raise
0