結果

問題 No.983 Convolution
ユーザー EnderedEndered
提出日時 2020-02-11 15:08:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,296 ms / 2,000 ms
コード長 3,061 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 183,436 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-01 07:50:31
合計ジャッジ時間 9,295 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif
ll modpow(ll x, ll b){
ll res = 1;
while(b){
if(b&1)res = res * x % MOD;
x = x * x % MOD;
b>>=1;
}
return res;
}
ll modinv(ll x){
return modpow(x, MOD-2);
}
bool was_output = false;
template<class t>
void output(t a){
if(was_output)cout << " ";
cout << a;
was_output = true;
}
void outendl(){
was_output = false;
cout << endl;
}
ll norpow(ll x, ll b){
ll res = 1;
while(b){
if(b&1)res = res * x;
x = x * x;
b>>=1;
}
return res;
}
vector<ll> primes;
void set_primes(){
vector<bool> flag(40005, true);
for(int i=2;i<flag.size();++i){
if(flag[i]){
primes.push_back(i);
for(int j=i*2;j<flag.size();j+=i){
flag[j] = false;
}
}
}
}
map<ll, ll> prime_melt(ll x){
map<ll, ll> res;
foreach(i, primes){
if(i*i>x)break;
int cnt = 0;
while(x%i==0){
++cnt;
x /= i;
}
if(cnt){
res[i] = cnt;
}
}
if(x!=1){
res[x] = 1;
}
return res;
}
ll gcd(ll a, ll b){
while(b){
a%=b;
swap(a, b);
}
return a;
}
int main(){
int n;
cin >> n;
set_primes();
vector<ll> line(n);
foreach(i, line){
cin >> i;
}
int cnt = [](vector<ll> line){
int res = 0;
foreach(i, line){
if(i!=-1)++res;
}
return res;
}(line);
if(cnt==0){
cout << -1 << endl;
return 0;
}
map<ll, ll> m;
bool flag = false;
foreach(i, line){
if(i==-1)continue;
map<ll, ll> res = prime_melt(i);
map<ll, ll> nm;
if(flag){
foreach(j, res){
if(m.count(j.first)){
nm[j.first] = min(m[j.first], j.second);
}
}
}else{
nm = res;
}
flag = true;
m = nm;
}
ll res = 1;
foreach(i, m){
res *= norpow(i.first, i.second*2);
}
cout << res << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0