日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/4/16 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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<j≤n ) that?lcm(ai,aj) is minimum possible.
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<j≤n ) such that the value of?lcm(ai,aj) is minimum among all valid pairs?i,j? If there are multiple answers, you can print any.
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<bits/stdc++.h> 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<ans){ans=x;l=vis[x];r=i;}vis[x]=i;}sort(a+1,a+n+1);int m=unique(a+1,a+n+1)-a-1;for(int i=1;i<=a[m];++i){int cur=-1;for(int j=i;j<maxn;j+=i){if(vis[j]) {q[++cur]=j;if(cur>=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<<l<<' '<<r<<endl;}return 0; }


?

總結

以上是生活随笔為你收集整理的cf552 G Minimum Possible LCMn个数,求最小得一对lcm的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。