SGU 499

思路主要是枚舉因子

歸爲優美的暴力

橫向不通的時候,我們可以採用縱向枚舉

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1000000 + 10;
int ans[maxn];
int main(){
    int  n;
    while( scanf("%d", &n) != EOF){
        memset(ans, 0, sizeof(ans));

        int tt;
        int lichuan = 0;
        for(int i = 0; i < n; i++){
            scanf("%d", &tt);
            ans[tt]++;
            lichuan = max(lichuan, tt);
        }
        int ttt = 0;
        int F = 0;
        for(int i = 1; i <= lichuan; i++){
            ttt = 0;
//            printf("i = %d\n", i);
            for(int j = i; j <= lichuan; j+= i){
                ttt += ans[j];
                if(ttt >= 2) break;
            }
//            printf("ttt = %d\n", ttt);
            if(ttt >= 2)
            F = max(F, i);
        }
        printf("%d\n", F);
    }


    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章