結果
問題 | No.2954 Calculation of Exponentiation |
ユーザー |
![]() |
提出日時 | 2024-11-08 23:22:55 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 990 bytes |
コンパイル時間 | 2,417 ms |
コンパイル使用メモリ | 206,572 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 23:22:59 |
合計ジャッジ時間 | 3,494 ms |
ジャッジサーバー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 / sint 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;}