結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-08 22:23:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 669 bytes |
| コンパイル時間 | 2,277 ms |
| コンパイル使用メモリ | 193,480 KB |
| 最終ジャッジ日時 | 2025-01-17 12:38:37 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 WA * 3 RE * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | lint m,p; scanf("%d%lld%lld",&n,&m,&p);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:14:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | rep(i,n) scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
const int INF=1<<29;
int main(){
int n;
lint m,p; scanf("%d%lld%lld",&n,&m,&p);
vector<lint> a(n);
rep(i,n) scanf("%lld",&a[i]);
if(m==1){
puts("0");
return 0;
}
if(*max_element(a.begin(),a.end())>=m){
puts("1");
return 0;
}
lint mx=1;
rep(i,n){
lint t=a[i];
while(t%p==0) t/=p;
mx=max(mx,t);
}
if(mx==1){
puts("-1");
return 0;
}
return -1;
int ans=INF;
rep(i,n) if(a[i]>=2) {
lint tar=(m+a[i]-1)/a[i];
int cnt=0;
for(lint x=1;x<tar;x*=mx){
cnt++;
}
ans=min(ans,cnt+1);
}
printf("%d\n",ans);
return 0;
}