結果
| 問題 |
No.2954 Calculation of Exponentiation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-08 22:57:50 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,165 bytes |
| コンパイル時間 | 1,443 ms |
| コンパイル使用メモリ | 94,616 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 22:57:56 |
| 合計ジャッジ時間 | 5,145 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 12 WA * 1 RE * 15 |
ソースコード
#include <iostream>
#include <string>
#include <utility>
#include <map>
#include <cassert>
using namespace std;
using ll = long long;
int main () {
// 未証明だけど、とりあえず次のアルゴで動かす。
// まず、Aが整数でないと即死。 -> これは嘘です。
// Aが整数なら、できるだけ冪で表現する。(A = 1は0乗として扱う)
// それを使ってBを崩しに行って、整数になればOK
string A, B; cin >> A >> B;
auto f = [&] (string S) {
bool minus = false;
if (S.find('-') != string::npos) {
minus = true;
S = S.substr(1);
}
int d = S.find('.');
bool has = false;
for (int i = 0; i < d; i++) {
if (S[i] != '0') has = true;
}
if (!has) S = S.substr(d);
for (int i = 0; i < S.size() - 1; i++) {
if (S[i] == '.') swap(S[i], S[i + 1]);
}
S = S.substr(0, S.size() - 1);
int b = static_cast<int>(S.size() - 1);
for (int i = 0; i < S.size() - 1; i++) {
if (S[i] != '0') {
b = i;
break;
}
}
if (!minus) {
return make_pair(stoll(S.substr(b)), 10000LL);
}
return make_pair(10000LL, stoll(S.substr(b)));
};
auto&& [a, ad] = f(A);
auto&& [b, bd] = f(B);
// この先b側を反転させる可能性があるので、これを先に除く。
if (b == 0) {
cout << "Yes" << "\n";
return 0;
}
if (0 < a % ad && 0 < ad % a) {
cout << "No" << "\n";
return 0;
}
if (ad % a == 0) {
swap(a, ad);
swap(b, bd);
}
a /= ad;
ad = 1;
map<int, int> mp;
for (int i = 2; i <= a; i++) {
while (a % i == 0) {
a /= i;
mp[i]++;
}
}
int mi = 1000000000;
for (auto& v : mp) {
mi = min(mi, v.second);
}
if (mi == 1000000000) mi = 0;
assert(b % bd == 0);
if ((1LL * mi * b) % bd == 0) {
cout << "Yes" << "\n";
}
else {
cout << "No" << "\n";
}
}