結果
問題 | No.2954 Calculation of Exponentiation |
ユーザー |
![]() |
提出日時 | 2024-11-08 22:29:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 987 bytes |
コンパイル時間 | 2,068 ms |
コンパイル使用メモリ | 204,764 KB |
最終ジャッジ日時 | 2025-02-25 02:52:40 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; pair<ll, ll> num(string S) { const int L = S.size(); const string lf = S.substr(0, L - 5); const string rg = S.substr(L - 4, 4); return make_pair(stoll(lf + rg), 10000); } map<ll, ll> fac(ll n) { map<ll, ll> ret; for(ll p = 2; p * p <= n; p++) { while(n % p == 0) { n /= p; ret[p]++; } } if(n > 1) ret[n]++; return ret; } int main() { string A, B; cin >> A >> B; auto [x, y] = num(A); auto [z, w] = num(B); if(x == 10000 || z == 0) { cout << "Yes" << endl; } else { if(z < 0) { swap(x, y); z = abs(z); } auto fx = fac(x); auto fy = fac(y); for(auto &[p, e] : fy) { fx[p] -= e; if(fx[p] < 0) { cout << "No" << endl; return 0; } } for(auto &[p, e] : fx) { e *= z; if(e % w != 0) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } }