cf552 G Minimum Possible LCMn个数,求最小得一对lcm

 

You are given an array a consisting of n integers a1,a2,…,an
Your problem is to find such pair of indices i,j  (1≤i lcm(x,y)  is the least common multiple of x and y (minimum positive number such that both  x and  y are divisors of this number).
Input
The first line of the input contains one integer  n (2≤n≤106 ) — the number of elements in a .
The second line of the input contains nn integers a1,a2,…,an (1≤ai≤107 ), where ai  is the  i-th element of a .
Output
Print two integers  i and  j (1≤i 5
2 4 8 3 6
1 2
5
5 2 11 3 7
2 4
6
2 5 10 1 10 2
1 4
优美的暴力

#include
using namespace std;
const int maxn = 1e7 + 5;
typedef long long ll;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int n, x, p1, p2, vis[maxn], a[maxn];
ll q[maxn];
int gcd(int a,int b){
	if(!b)return a;
	return gcd(b,a%b);
}
int main(){
	while(scanf("%d",&n)!=EOF){
		ll ans=inf;
		int l,r;
		memset(vis,0,sizeof(vis));
		memset(a,0,sizeof(a));
		memset(q,0,sizeof(q));
		for(int i=1;i<=n;++i){
			scanf("%d",&x);
			a[i]=x;
			if(vis[x]&&x=1)break;
				}
			}  
			if(cur>=1){
			ll d= gcd(q[0],q[1]);  
			   if(ans>q[0]/d*q[1]){
					ans= q[0]/d*q[1];
					l=vis[q[0]];
					r=vis[q[1]];
				}
			}
		}
		if(l>r)swap(l,r);
		
		cout<


 

你可能感兴趣的:(基础数学)