結果
問題 |
No.2954 Calculation of Exponentiation
|
ユーザー |
![]() |
提出日時 | 2024-11-11 17:40:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,079 bytes |
コンパイル時間 | 590 ms |
コンパイル使用メモリ | 58,484 KB |
最終ジャッジ日時 | 2025-02-25 03:55:32 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘pii readrat()’: main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d.%d", &p, &q); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2954.cc: No.2954 Calculation of Exponentiation - yukicoder */ #include<cstdio> #include<cmath> #include<algorithm> #include<utility> using namespace std; /* typedef */ using pii = pair<int,int>; /* subroutines */ template <typename T> T gcd(T m, T n) { // m >= 0, n >= 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } pii readrat() { int p, q; scanf("%d.%d", &p, &q); int n = abs(p) * 10000 + q, d = 10000; if (p < 0) n = -n; int g = gcd(abs(n), d); n /= g, d /= g; return {n, d}; } /* main */ int main() { auto [an, ad] = readrat(); auto [bn, bd] = readrat(); if (bn < 0) { swap(an, ad); bn = -bn; } //printf(" a=%d/%d, b=%d/%d\n", an, ad, bn, bd); if (ad == 1) { if (bd == 1) { puts("Yes"); return 0; } int x0 = 1, x1 = an + 1; while (x0 + 1 < x1) { int x = (x0 + x1) / 2; if (pow(x, bd) > an) x1 = x; else x0 = x; } if (pow(x0, bd) == an) { puts("Yes"); return 0; } } puts("No"); return 0; }