codeforces 1349 A 思维

 

题意:给了n个数,求任意一对数的lcm组成的数组的gcd。

思路:对每个数质因子分解,把每个数出现的次数存入数组中。

  把每个质因子出现的次数从小进行排序。

  对于质因子p。

  如果p出现了n次,则选择第二小的幂次k,贡献即为pk

  如果p出现了n-1次,则选择第一小的幂次k,贡献即为pk

  出现小于n-1次,则没贡献。

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <vector> 
// #include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sp ' '
#define endl '\n'
#define inf  0x3f3f3f3f;
#define FOR(i,a,b) for( int i = a;i <= b;++i)
#define bug cout<<"--------------"<<endl
#define P pair<int, int>
#define fi first
#define se second
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define sca3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define sca2(a,b) scanf("%d %d",&(a),&(b))
#define sca(a) scanf("%d",&(a));
#define sca3ll(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define sca2ll(a,b) scanf("%lld %lld",&(a),&(b))
#define scall(a) scanf("%lld",&(a));


using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a, ll b, ll mod){ll sum = 1;while (b) {if (b & 1) {sum = (sum * a) % mod;b--;}b /= 2;a = a * a % mod;}return sum;}

const double Pi = acos(-1.0);
const double epsilon = Pi/180.0;
const int maxn = 2e5+10;
vector<int>v[maxn];
int main()
{
    //freopen("input.txt", "r", stdin);
    
    int n;
    cin>>n;
    rep(i,1,n){
        int x;
        cin>>x;
        for(int j = 2;j*j <= x; ++j){
            int cnt = 0;
            while(x % j == 0){
                x /= j;
                cnt++;
            }
            if(cnt) v[j].pb(cnt);
        }
        if(x > 1) v[x].pb(1);
    }
    ll sum = 1;
   // cout<<v[2].size()<<sp<<v[5].size()<<endl;
    rep(i,2,200000){
        if(v[i].size() == n){
            sort(v[i].begin(), v[i].end());
            sum *= pow(i,v[i][1]);
        }
        else if(v[i].size() == n-1){
            sort(v[i].begin(), v[i].end());
            sum *= pow(i,v[i][0]);
        }
      //  cout<<sum<<endl;
    }
    cout<<sum<<endl;
}

 

posted @ 2020-07-14 21:45  阿斯水生产线  阅读(106)  评论(0编辑  收藏  举报