結果

問題 No.1330 Multiply or Divide
ユーザー shiomusubi496
提出日時 2021-01-08 21:47:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 536 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 168,272 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-16 11:03:26
合計ジャッジ時間 4,950 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1e18;
signed main(){
    int N,M,P,mx=0;cin>>N>>M>>P;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        mx=max(mx,A[i]);
    }
    int ans=INF,m=(M+mx-1)/mx;
    for(int i=0;i<N;i++){
        int a=1,b=1,cnt=1;
        while(A[i]%P==0)A[i]/=P,a++;
        if(A[i]==1){
            if(m==1)ans=1;
            continue;
        }
        while(b<m)b*=A[i],cnt+=a;
        ans=min(ans,cnt);
    }
    cout<<(ans==INF?-1:ans)<<endl;
}
0