結果

問題 No.1330 Multiply or Divide
ユーザー furafura
提出日時 2021-01-08 22:28:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 569 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 195,536 KB
最終ジャッジ日時 2025-01-17 12:45:40
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         lint m,p; scanf("%d%lld%lld",&n,&m,&p);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,n) scanf("%lld",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

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;
	}

	lint mx=*max_element(a.begin(),a.end());
	if(mx>=m){
		puts("1");
		return 0;
	}

	lint mx2=1;
	for(lint x:a){
		while(x%p==0) x/=p;
		mx2=max(mx2,x);
	}
	if(mx2==1){
		puts("-1");
		return 0;
	}

	lint tar=(m+mx-1)/mx;
	int cnt=0;
	for(lint x=1;x<tar;x*=mx2) cnt++;
	printf("%d\n",cnt+1);

	return 0;
}
0