結果

問題 No.1224 I hate Sqrt Inequality
ユーザー uk714
提出日時 2020-09-12 01:50:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 174,468 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-26 18:23:00
合計ジャッジ時間 2,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://yukicoder.me/problems/no/1224
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// 素因数分解
map<int, int> factorize(int n) {
    map<int, int> V;

    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            V[i]++;
            n /= i;
        }
    }
    if (n > 1)
        V[n]++;
    return V;
}

void solve() {
    // ① これ以上、既約分数になるまで約分(これ以上、約分できない状態にする)
    // ② 分母を素因数分解して「2と5」以外の素数を持つ場合、無限小数
    // ③ 上記以外は、有限小数
    int A, B;
    cin >> A >> B;
    int t = gcd(A, B);
    A /= t;
    B /= t;
    auto fa = factorize(B);
    bool mugen = false;
    for (auto &x : fa) {
        if (x.first != 2 && x.first != 5) {
            mugen = true;
        }
    }
    if (mugen) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}
0