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 |
要考虑 1 1线性筛素数~ 附代码(供参考) 大牛们看了不要笑话~ Problem: 3048 User: 810974380 Memory: 236K Time: 0MS Language: C++ Result: Accepted Source Code #include<iostream> #include<string.h> #include<algorithm> using namespace std; #define Max 30001 bool flag[Max];int i,j,n,s[5001]; void getp() { memset(flag,true,sizeof(flag)); for(i=3;i<1000;i+=2) { if(flag[i]) for(j=3;i*j<=Max;j+=2) if(flag[i]) flag[i*j]=false; } for(i=4;i<=Max;i+=2) flag[i]=false; } int main() { getp(); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&s[i]); sort(s,s+n); for(i=s[n-1];i>=1;i--) { for(j=n-1;j>=0;j--) { if((flag[i])&&s[j]%i==0) break; } if((flag[i])&&s[j]%i==0) break; } printf("%d\n",s[j]); system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator