一、视频讲解
蓝桥杯真题讲解:公因数匹配(数论:分解质因数)

二、正解代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;
map<int,vector<int>>st;
int cnt = 0;
void test(){
for(int i = 2; i <= 1e6; i ++){
int tmp = i;
bool flag = true;
for(int j = 2; j <= tmp / j; j ++){
if(tmp % j == 0)
{
flag = false;
break;
}
}
cnt += flag;
}
cout << cnt << endl;
}
void prim(int x, int pos) {
for(int i = 2; i <= x / i; i ++){
if(x % i)
continue;
st[i].push_back(pos);
while(x % i == 0){
x /= i;
}
}
if(x > 1){
st[x].push_back(pos);
}
return;
}
void solve()
{
int n; cin >> n;
for(int i = 1; i <= n; i ++)
{
int x; cin >> x;
prim(x, i);
}
pair<int,int> ans = {INF, INF};
for(auto [x, y]: st){
if(y.size() < 2){
continue;
}
if(y[0] < ans.first){
ans = {y[0], y[1]};
}else if(y[0] == ans.first){
if(y[1] < ans.second){
ans = {y[0], y[1]};
}
}
}
cout << ans.first << " " << ans.second << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
while(t--)
solve();
}