結果
| 問題 |
No.2954 Calculation of Exponentiation
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2024-11-08 23:22:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 990 bytes |
| コンパイル時間 | 2,131 ms |
| コンパイル使用メモリ | 200,180 KB |
| 最終ジャッジ日時 | 2025-02-25 03:11:56 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
fast_io();
string a, b;
cin >> a >> b;
if (b == "0.0000") {
cout << "Yes" << endl;
return 0;
}
int n = a.size(), m = b.size();
// a = p / q, b = r / s
int p = stoi(a.substr(0, n - 5) + a.substr(n - 4, 4));
int q = 10000;
int g = gcd(p, q);
p /= g;
q /= g;
if (b[0] == '-') {
swap(p, q);
b = b.substr(1);
}
int r = stoi(b.substr(0, m - 5) + b.substr(m - 4, 4));
int s = 10000 / gcd(r, 10000);
if (q != 1) {
cout << "No" << endl;
return 0;
}
int A = stoi(a.substr(0, n - 5));
vector<pair<int, int>> pf;
for (int i = 2; i * i <= A; i++) {
if (A % i == 0) {
int cnt = 0;
while (A % i == 0) {
A /= i;
cnt++;
}
pf.push_back({i, cnt});
}
}
if (A > 1) {
pf.push_back({A, 1});
}
for (auto [_, cnt] : pf) {
if (cnt % s != 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
eve__fuyuki