链接
https://codeforces.com/contest/1154/problem/G
题解
l
c
m
(
a
,
b
)
=
a
b
(
a
,
b
)
lcm(a,b)=\frac{ab}{(a,b)}
lcm(a,b)=(a,b)ab
显然
a
a
a和
b
b
b都是
(
a
,
b
)
(a,b)
(a,b)的倍数
开一个权值数组,记录每种大小的数字分别有几个
然后我枚举分母
g
g
g,去遍历
g
g
g的倍数,最小的两个作为分子
输出方案确实比较费事…
代码
#include <bits/stdc++.h>
#define eps 1e-8
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define cl(x) memset(x,0,sizeof(x))
#define mod 1000000007ll
#define maxn 10000010
using namespace std;
typedef long long ll;
ll read(ll x=0)
{
int c, f=1;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-48;
return f*x;
}
ll cnt[maxn], N, a[maxn], id[maxn];
bool cmp(ll x, ll y){return a[x]<a[y];}
int main()
{
ll i, res, g, lastg;
vector<ll> ans, num, out;
N=read();
for(i=1;i<=N;i++)
{
a[i]=read();
cnt[a[i]]++;
id[i]=i;
}
for(g=1;g<maxn;g++)
{
num.clear();
for(i=g;i<maxn and num.size()<2;i+=g)
{
if(num.size()==1)
{
if(cnt[i])
{
num.push_back(i);
}
}
else
{
if(cnt[i]==1)
{
num.push_back(i);
}
else if(cnt[i]>=2)
{
num.push_back(i);
num.push_back(i);
}
}
}
if(num.size()<2)continue;
if(ans.empty() or num[0]*num[1]/g < ans[0]*ans[1]/lastg)
{
ans=num;
lastg=g;
}
}
sort(id+1,id+N+1,cmp);
ll p=0;
for(i=1;i<=N and p<=1;i++)
{
if(a[id[i]]==ans[p])
{
out.push_back(id[i]);
p++;
}
}
sort(out.begin(),out.end());
for(auto x:out)cout<<x<<' ';
return 0;
}