結果
| 問題 |
No.2954 Calculation of Exponentiation
|
| コンテスト | |
| ユーザー |
sai
|
| 提出日時 | 2024-11-09 13:38:19 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,954 bytes |
| コンパイル時間 | 3,347 ms |
| コンパイル使用メモリ | 249,000 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-09 13:38:24 |
| 合計ジャッジ時間 | 3,944 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/math>
void solve() {
double A, B; std::cin >> A >> B;
int a = A * 10000, b = B * 10000;
if (b == 0) {
std::cout << "Yes\n";
} else if (b > 0) {
if (a % 10000 != 0) {
std::cout << "No\n";
} else {
int cnt2 = 4, cnt5 = 4;
while (cnt2 && b % 2 == 0) {
cnt2--;
b /= 2;
}
while (cnt5 && b % 5 == 0) {
cnt5--;
b /= 5;
}
a /= 10000;
int p = 1;
for (;cnt2--;) {
p *= 2;
}
for (;cnt5--;) {
p *= 5;
}
for (int i = 1; atcoder::pow_mod(i, p, 1 << 30) <= a; i++) {
if (atcoder::pow_mod(i, p, 1 << 30) == a) {
std::cout << "Yes\n";
return;
}
}
std::cout << "No\n";
}
} else {
if (a > 10000) {
std::cout << "No\n";
} else if (a == 10000) {
std::cout << "Yes\n";
} else {
if (10000 % a != 0) {
std::cout << "No\n";
} else {
a = 10000 / a * 10000;
b *= -1;
if (a % 10000 != 0) {
std::cout << "No\n";
} else {
int cnt2 = 4, cnt5 = 4;
while (cnt2 && b % 2 == 0) {
cnt2--;
b /= 2;
}
while (cnt5 && b % 5 == 0) {
cnt5--;
b /= 5;
}
a /= 10000;
int p = 1;
for (;cnt2--;) {
p *= 2;
}
for (;cnt5--;) {
p *= 5;
}
for (int i = 1; atcoder::pow_mod(i, p, 1 << 30) <= a; i++) {
if (atcoder::pow_mod(i, p, 1 << 30) == a) {
std::cout << "Yes\n";
return;
}
}
std::cout << "No\n";
}
}
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int testcases = 1;
// std::cin >> testcases;
for (;testcases--;) {
solve();
}
return 0;
}
sai