結果

問題 No.1330 Multiply or Divide
ユーザー shu8Creamshu8Cream
提出日時 2021-01-08 22:21:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,053 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 214,644 KB
実行使用メモリ 11,772 KB
最終ジャッジ日時 2024-04-28 03:40:15
合計ジャッジ時間 9,036 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 10 ms
7,620 KB
testcase_04 AC 10 ms
7,592 KB
testcase_05 AC 9 ms
7,680 KB
testcase_06 AC 30 ms
8,356 KB
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 WA -
testcase_25 AC 10 ms
7,584 KB
testcase_26 AC 10 ms
7,588 KB
testcase_27 AC 10 ms
7,680 KB
testcase_28 AC 9 ms
7,680 KB
testcase_29 AC 10 ms
7,680 KB
testcase_30 WA -
testcase_31 AC 10 ms
7,680 KB
testcase_32 AC 9 ms
7,588 KB
testcase_33 AC 9 ms
7,680 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
*    author:  shu8Cream
*    created: 08.01.2021 21:06:40
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

const int MX = 1000005;

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n+1), f(n+1) {
        f[0] = f[1] = -1;
        for(ll i=2; i <= n; ++i){
            if(f[i]) continue;
            primes.push_back(i);
            f[i]=i;
            for(ll j=i*i; j <= n; j+=i){
                if(!f[j]) f[j]=i;
            }
        }
    }
    bool isPrime(int x){ return f[x] == x;}
    //xの素因数分解の要素の配列
    vector<int> factorList(int x){
        vector<int> res;
        while(x != 1){
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    //xの素因数分解の要素をRunLength圧縮
    vector<P> factor(int x){
        vector<int> fl = factorList(x);
        if(fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for(int p:fl){
            if(res.back().first == p){
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    Sieve sieve(1e6);
    int n,m,p;
    cin >> n >> m >> p;
    vi a(n);
    rep(i,n) cin >> a[i];
    
    map<int, int> mp;
    rep(i,n){
        auto f = sieve.factor(a[i]);
        for(auto p : f){
            mp[p.first] += p.second;
        }
    }
    bool f = true;
    int tmp=0;
    for(auto p : mp){
        if(p.first!=2) f=false;
        tmp = p.first;
    }
    if(f){
        cout << -1 << endl;
        return 0;
    }
    int cnt = 0;
    rep(i,n) if(a[i]%tmp==0) cnt=max(cnt, a[i]);
    while(cnt%p==0){
        cnt/=p;
    }
    tmp = 1;
    int ans=0;
    while(m>tmp){
        tmp*=cnt;
        ans++;
    }
    cout << ans << endl;
}
0