結果

問題 No.1250 汝は倍数なりや?
ユーザー Manuel1024
提出日時 2021-03-11 01:49:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 79,080 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-10-12 16:37:45
合計ジャッジ時間 5,215 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37 WA * 1 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
int main(){
    ll n, h;
    cin >> n >> h;
    vector<ll> a(n);
    for(auto &p: a) cin >> p;
    
    vector<P> hfactor;
    for(int i = 2; h > 1; i++){
        if(h % i == 0){
            int cnt = 0;
            while(h > 1 && h % i == 0){
                cnt++;
                h /= i;
            }
            hfactor.push_back(make_pair(i, cnt));
        }
    }
    vector<int> countfac(hfactor.size(), 0);
    for(auto p: a){
        p = abs(p);
        for(int i = 0; i < hfactor.size(); i++){
            if(hfactor[i].second <= countfac[i]) continue;
            while(p > 1 && p % hfactor[i].first == 0){
                countfac[i]++;
                p /= hfactor[i].first;
            }
        }
    }

    string ans = "YES";
    for(int i = 0; i < hfactor.size(); i++){
        if(hfactor[i].second > countfac[i]) ans = "NO";
    }
    cout << ans << endl;
    return 0;
}
0