Codeforces Round #552 (Div. 3)G. Minimum Possible LCM【埃筛】

G. Minimum Possible LCM

time limit per test

4 seconds

memory limit per test

1024 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn integers a1,a2,…,ana1,a2,…,an.

Your problem is to find such pair of indices i,ji,j (1≤i<j≤n1≤i<j≤n) that lcm(ai,aj)lcm(ai,aj) is minimum possible.

lcm(x,y)lcm(x,y) is the least common multiple of xx and yy (minimum positive number such that both xx and yy are divisors of this number).

Input

The first line of the input contains one integer nn (2≤n≤1062≤n≤106) — the number of elements in aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1071≤ai≤107), where aiai is the ii-th element of aa.

Output

Print two integers ii and jj (1≤i<j≤n1≤i<j≤n) such that the value of lcm(ai,aj)lcm(ai,aj) is minimum among all valid pairs i,ji,j. If there are multiple answers, you can print any.

Examples

input

Copy

5
2 4 8 3 6

output

Copy

1 2

input

Copy

5
5 2 11 3 7

output

Copy

2 4

input

Copy

6
2 5 10 1 10 2

output

Copy

1 4

 

 

分析:LCM(i,j)=i*j/gcd,a[i]<=1e7,那么gcd也<=1e7,我们就可以枚举gcd,记录一下a[i]是否出现,然后用gcd筛出i,j。

总复杂度应该是O(NlogN)

#include "bits/stdc++.h"

using namespace std;
int vis[10000004];


int main() {
    int n;
    int x;
    cin >> n;
    memset(vis, 0, sizeof(vis));
    int ansi, ansj;
    long long ans = 1e14;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &x);
        if (!vis[x])vis[x] = i;
        else {
            if (ans > x) {
                ansi = vis[x];
                ansj = i;
                ans = x;
            }

        }
    }
    int ti, tj;
    for (int i = 1; i < 10000004; ++i) {
        ti = tj = 0;
        int temp;
        for (int j = i; j < 10000004; j += i) {
            if (!vis[j])continue;
            if (!ti) {
                ti = vis[j];
                temp = j;
            } else {
                tj = vis[j];
                if (ans > 1LL * temp * j / i) {
                    ans = 1LL * temp * j / i;
                    ansi = ti;
                    ansj = tj;
                }
            }
        }
    }
    if (ansi > ansj)swap(ansi, ansj);
    printf("%d %d\n", ansi, ansj);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值