結果
問題 | No.2954 Calculation of Exponentiation |
ユーザー |
|
提出日時 | 2024-11-09 02:33:25 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,245 bytes |
コンパイル時間 | 396 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 76,288 KB |
最終ジャッジ日時 | 2024-11-09 02:33:29 |
合計ジャッジ時間 | 3,766 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 WA * 2 |
ソースコード
from sys import stdinfrom random import randintfrom collections import deque, defaultdict as ddfrom copy import deepcopyinput = stdin.readlineMOD = 998244353INF = 1 << 60xor = randint(100, INF)def extended_gcd(a, b):if b == 0:return a, 1, 0else:g, x, y = extended_gcd(b, a % b)return g, y, x - (a // b) * ydef mod_inverse(a, m):_, x, _ = extended_gcd(a, m)return (x % m + m) % mdef fast_mod_pow(x, p):res = 1t = xz = pwhile z > 0:if z % 2 == 1:res = (res * t)t = (t * t)z //= 2return resdef main():a, b = map(float, input().split())div = 10000a = int(a*div)b = int(b*div)g1 = extended_gcd(a, div)[0]if not (div//g1==1 and b > 0 or a//g1==1 and b < 0):print("No")returnif b < 0:a = div//g1else:a //= g1l = 0r = 1<<30g2 = div//extended_gcd(b, div)[0]while l+1 < r:m = (l+r)//2if fast_mod_pow(m, g2) <= a:l = melse:r = mif fast_mod_pow(l, g2)==a or fast_mod_pow(r, g2)==a:print("Yes")else:print("No")if __name__ == "__main__":main()