結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-08 22:55:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,053 bytes |
| コンパイル時間 | 2,189 ms |
| コンパイル使用メモリ | 206,128 KB |
| 最終ジャッジ日時 | 2025-01-17 13:46:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 35 MLE * 11 |
ソースコード
/**
* 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(1e8);
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;
}