CodeForece1108B. Divisors of Two Integers (思维水题)

在这里插入图片描述
题意: 给出一个包含x和y所有因子的乱序列表(重复因子重复), 找出x和y

思路: 首先可以想到最大的因子一定是最大的那个数, 而对于其他的因子我们排除一下即可

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const LL maxn = 1e4+10;

int main()
{
    int n, d[maxn];
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> d[i];
    sort(d+1, d+n+1);

    cout << d[n] << " ";
    for(int i = n; i>0; i--)
        if(d[n]%d[i]!=0 || d[i]==d[i-1]){
            cout << d[i] << endl;
            break;
        }

	return 0;
}

猜你喜欢

转载自blog.csdn.net/a1097304791/article/details/86655071