• ssu 499 Greatest Greatest Common Divisor


    499. Greatest Greatest Common Divisor

    Time limit per test: 0.5 second(s)
    Memory limit: 262144 kilobytes
    input: standard
    output: standard

    Andrew has just made a breakthrough in sociology: he realized how to predict whether two persons will be good friends or not. It turns out that each person has an inner friendship number (a positive integer). And the quality of friendship between two persons is equal to the greatest common divisor of their friendship number. That means there are prime people (with a prime friendship number) who just can't find a good friend, andWait, this is irrelevant to this problem. You are given a list of friendship numbers for several people. Find the highest possible quality of friendship among all pairs of given people.
    Input
    The first line of the input file contains an integer n () — the number of people to process. The next n lines contain one integer each, between 1 and (inclusive), the friendship numbers of the given people. All given friendship numbers are distinct.
    Output
    Output one integer — the highest possible quality of friendship. In other words, output the greatest greatest common divisor among all pairs of given friendship numbers.
    Example(s)
    sample input
    sample output
    4
    9
    15
    25
    16
    
    5
    
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <map>
    #include <cmath>
    #include <queue>
    #include <cstring>
    #include <set>
    #include <stack>
    #include <string>
    #define LL long long
    #define maxn 100010
    #define mod 1000000007
    #define INF 2000000
    #define MAX 16000010
    #define eps 1e-6
    using namespace std;
    
    bool vi[maxn*10] ;
    int Max ;
    int max(int a ,int b){ return a > b ? a : b ;}
    
    void insert( int n )
    {
        int m ,i ,k ;
        m = sqrt(n+0.5) ;
        for( i = 1 ; i <= m ;i++)if(n%i == 0)
        {
            k = n/i ;
            if(vi[i])
            {
                Max = max(Max,i) ;
            }
            else vi[i] = true ;
            if(vi[k]&&k != i)
            {
                Max = max(Max,k) ;
            }
            else vi[k] = true ;
        }
    }
    int main()
    {
        int i ,m , tt , j , n ;
        int L , R , mid ;
        // freopen("in.txt","r",stdin) ;
       // 枚举每个数的因子是可以过的  
        while( scanf("%d",&n) != EOF)
        {
            memset(vi,0,sizeof(vi)) ;
             Max = 0 ;
             for( i = 1 ; i <= n ;i++ ){
                 scanf("%d",&m) ;
                 insert(m) ;
             }
            printf("%d
    ",Max) ;
        }
        return 0 ;
    }
    
  • 相关阅读:
    七牛上传图片视频demo
    JavaScript数组及相关方法
    Math对象产生随机数一个小应用
    JavaScript 开发进阶:理解 JavaScript 作用域和作用域链
    HTML5 中的meter 标签的样式设置
    jQuery报错:Uncaught ReferenceError: $ is not defined
    每次打开office 2013都提示配置进度,必须得等他下完然后重启,重启完了在打开,还是提示配置进度,怎么解决
    CSS小技巧收藏
    DOM中元素节点、属性节点、文本节点的理解13.3
    (转)如果知道dll文件是面向32位系统还是面向64位系统的?
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3596475.html
Copyright © 2020-2023  润新知