Warning: session_start(): open(/tmp/sess_0fa3fadc49afd1b5a03a4d621ee25130, O_RDWR) failed: No space left on device (28) in /data/wiki/inc/init.php on line 239

Warning: session_start(): Failed to read session data: files (path: ) in /data/wiki/inc/init.php on line 239

Warning: Cannot modify header information - headers already sent by (output started at /data/wiki/inc/init.php:239) in /data/wiki/inc/auth.php on line 430

Warning: Cannot modify header information - headers already sent by (output started at /data/wiki/inc/init.php:239) in /data/wiki/inc/actions.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at /data/wiki/inc/init.php:239) in /data/wiki/lib/tpl/dokuwiki/main.php on line 12
2020-2021:teams:manespace:codeforc_round_641_div2_problem_c [CVBB ACM Team]

用户工具

站点工具


2020-2021:teams:manespace:codeforc_round_641_div2_problem_c

Orac and LCM

题意

给定长为 n ($2≤n≤10^5$)的正整数序列{s1,s2,…,sn},求由任意两元素 LCM(最小公倍数)组成新序列{a1,a2,…,an}的 GCD(最大公约数)

题解

啊好,还没写呢


AC代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const ll mod = 998244353;
const int maxn = 2e5 + 5; 
 
vector<int> ep[maxn];
 
ll qpow(int k, ll b){
	ll res = 1;
	while(b){
		if(b & 1) res *= k;
		k *= k;
		b >>= 1;
	}
	return res;
}
 
int main(){
	int n;	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		int t;	scanf("%d", &t);
		for(int i = 2; i * i <= t; ++i){
			ll cnt = 0;
			while(t % i == 0){
				t /= i;
				++cnt;
			}
			ep[i].push_back(cnt);
		}
		if(t != 1) ep[t].push_back(1);
	}
 
	ll ans = 1;
	for(int i = 1; i <= maxn; ++i){
		if(ep[i].size() >= n - 1){
			sort(ep[i].begin(), ep[i].end());
			if(ep[i].size() == n) ans *= qpow(i, ep[i][1]); 
			else ans *= qpow(i, ep[i][0]); 
		}
	}
	printf("%lld", ans);
}
2020-2021/teams/manespace/codeforc_round_641_div2_problem_c.1589528842.txt.gz · 最后更改: 2020/05/15 15:47 由 intouchables