杂题

发布时间:2014-10-22 12:03:32编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"杂题",主要涉及到杂题方面的内容,对于杂题感兴趣的同学可以参考一下。

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 primepeople (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 /* * Author: ******* * Created Time: 2013/8/17 18:57:51 * File Name: C.cpp * solve: C.cpp */ #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<map> #include<stack> #include<set> #include<iostream> #include<vector> #include<queue> using namespace std; #define sz(v) ((int)(v).size()) #define rep(i, n) for (int i = 0; i < (n); ++i) #define repf(i, a, b) for (int i = (a); i <= (b); ++i) #define repd(i, a, b) for (int i = (a); i >= (b); --i) #define clr(x) memset(x,0,sizeof(x)) #define clrs( x , y ) memset(x,y,sizeof(x)) #define out(x) printf(#x" %d\n", x) #define sqr(x) ((x) * (x)) typedef int LL; const int INF = 1000000000; const double eps = 1e-8; const int maxn = 1000010; int sgn(const double &x) { return (x > eps) - (x < -eps); } int used[maxn]; int main() { //freopen("in.txt","r",stdin); int n; scanf("%d",&n); clr(used); int maxi = 0; for(int i = 0;i<n;++i) { int a; scanf("%d",&a); used[a] = 1; maxi = max(maxi,a); } int ans = 0; for(int i = maxi;i>=1;--i) { int num = 0; for(int j = i;j<=maxi;j+=i) { if(used[j]) { num++; if(num>1) { ans = i; goto here; } } } } here: cout<<ans<<endl; return 0; }


上一篇:UVA 11149 Power of Matrix 倍增法
下一篇:hibernate 1+n问题

相关文章

关键词: 杂题

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款