結果

問題 No.2954 Calculation of Exponentiation
ユーザー lam6er
提出日時 2025-03-26 15:46:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,717 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 57,856 KB
最終ジャッジ日時 2025-03-26 15:47:18
合計ジャッジ時間 2,520 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import math
def parse_number(s):
is_negative = False
if s.startswith('-'):
is_negative = True
s = s[1:]
parts = s.split('.')
integer_part = parts[0]
fractional_part = parts[1] if len(parts) > 1 else '0000'
fractional_part = fractional_part.ljust(4, '0')[:4] # Ensure exactly four digits
numerator = int(integer_part) * 10000 + int(fractional_part)
denominator = 10000
g = math.gcd(abs(numerator), denominator)
reduced_num = numerator // g
reduced_den = denominator // g
if is_negative:
reduced_num = -reduced_num
return reduced_num, reduced_den
def factorize(n):
factors = {}
if n == 0:
return factors
n = abs(n)
while n % 2 == 0:
factors[2] = factors.get(2, 0) + 1
n = n // 2
i = 3
max_i = int(math.sqrt(n)) + 1
while i <= max_i and n > 1:
while n % i == 0:
factors[i] = factors.get(i, 0) + 1
n = n // i
max_i = int(math.sqrt(n)) + 1
i += 2
if n > 1:
factors[n] = 1
return factors
a_str, b_str = input().split()
a_num, a_den = parse_number(a_str)
b_num, b_den = parse_number(b_str)
if b_num == 0:
print("Yes")
else:
num_factors = factorize(a_num)
den_factors = factorize(a_den)
primes = set(num_factors.keys()).union(set(den_factors.keys()))
r = b_num
s = b_den
all_ok = True
for p in primes:
e = num_factors.get(p, 0)
f = den_factors.get(p, 0)
total_exp = (e - f) * r
if total_exp % s != 0:
all_ok = False
break
if (total_exp // s) < 0:
all_ok = False
break
print("Yes" if all_ok else "No")
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0