Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
附上简单理解的代码#include<cstdio> #include<cmath> #include<cstring> int a[20005]; int prim(int x) { if(x==1)return 0; int i; for(i=2;i<=sqrt((double)x);i++) { if(x%i==0)return 0; } return 1; } int main() { int i,n,b,ansprim,ansb,ans; memset(a,0,sizeof(a)); for(i=2;i<20001;i++) { if(prim(i))a[i]=i; } while(scanf("%d",&n)!=EOF) { ans=0; for(i=1;i<=n;i++) { scanf("%d",&b); for(int j=b;j>=1;j--) { if(a[j]!=0) { if(b%a[j]==0) { ansprim=a[j]; break; } } } if(ans<ansprim) { ans=ansprim; ansb=b; } } //printf("%d\n",ans); printf("%d\n",ansb); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator