結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
theory_and_me
|
| 提出日時 | 2019-10-26 01:13:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,984 bytes |
| コンパイル時間 | 1,785 ms |
| コンパイル使用メモリ | 179,212 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 11:07:15 |
| 合計ジャッジ時間 | 2,830 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
map<ll, ll> prime_factorization(ll x){
map<ll, ll> mp;
bool flag = true;
while(flag){
ll sqx = sqrt(x)+1;
for(ll j=2;j<sqx+1;j++){
if(x%j==0){
mp[j]++;
x/=j;
break;
}
if(j==sqx) flag = false;
}
}
if(x!=1){
mp[x]++;
}
return mp;
}
ll Euclid(ll A, ll B){
if(A<B) swap(A, B);
ll C = B;
while(C != 0){
C = A%B;
A = B;
B = C;
}
return A;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<ll> A(N);
REP(i, N) cin >> A[i];
vector<ll> B(N);
REP(i, N){
ll tmp = 1;
auto mp = prime_factorization(A[i]);
for(auto x: mp){
tmp *= x.first;
}
B[i] = tmp;
}
map<ll, ll> mp[55];
mp[0][0] = 1;
REP(i, N){
for(auto x:mp[i]){
ll val = x.first;
ll cnt = x.second;
mp[i+1][val] += cnt;
mp[i+1][Euclid(val, A[i])] += cnt;
}
}
cout << mp[N][1] << endl;
return 0;
}
theory_and_me