結果

問題 No.1250 汝は倍数なりや?
ユーザー outline
提出日時 2020-10-09 21:38:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 1,000 ms
コード長 1,788 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 134,372 KB
最終ジャッジ日時 2025-01-15 04:11:32
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, H, A;
    cin >> N >> H;
    map<int, int> mp;
    vector<int> prime;
    for(int i = 2; (ll)i * i <= H; ++i){
        if(H % i == 0)  prime.emplace_back(i);
        while(H % i == 0){
            ++mp[i];
            H /= i;
        }
    }
    if(H != 1){
        mp[H] = 1;
        prime.emplace_back(H);
    }
    map<int, int> mp2;
    for(int i = 0; i < N; ++i){
        cin >> A;
        if(A == 0){
            cout << "YES\n";
            return 0;
        }
        if(A < 0)   A = -A;
        int j = 0;
        while(j < (int)prime.size() && A != 1){
            while(A % prime[j] == 0){
                ++mp2[prime[j]];
                A /= prime[j];
            }
            ++j;
        }
    }
    for(int p : prime){
        if(mp[p] > mp2[p]){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}
0