結果

問題 No.2954 Calculation of Exponentiation
ユーザー 👑 binap
提出日時 2024-10-19 11:09:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 68,120 KB
最終ジャッジ日時 2024-10-24 02:07:31
合計ジャッジ時間 2,841 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict
import math

class Sieve:
    def __init__(self, n=1):
        self.n = n
        self.f = [0] * (n + 1)
        self.primes = []
        self._sieve()

    def _sieve(self):
        self.f[0] = self.f[1] = -1
        for i in range(2, self.n + 1):
            if self.f[i]:
                continue
            self.primes.append(i)
            self.f[i] = i
            for j in range(i * i, self.n + 1, i):
                if not self.f[j]:
                    self.f[j] = i

    def factor(self, x):
        res = []
        for p in self.primes:
            count = 0
            while x % p == 0:
                x //= p
                count += 1
            res.append((p, count))
        if x != 1:
            res.append((x, 1))
        return res

def solve():
    # Read a single line of input, split by space, and map to float
    A, B = map(float, input().split())
    a = round(A * 10000)
    b = round(B * 10000)

    sieve = Sieve(100005)
    factors = sieve.factor(a)

    ans = "Yes"
    for p, num in factors:
        if p == 2 or p == 5:
            num -= 4
        if num * b < 0:
            ans = "No"
        if num * b % 10000 != 0:
            ans = "No"
    
    print(ans)

if __name__ == "__main__":
    solve()
0