标签:声明 appear typedef one class cal war number integer
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。
Description
Input
Output
Sample Input
4
36
38
40
42
Sample Output
38
Hint
Source
我连线性筛都写挂了一次,真是没救了...
1 //It is made by ljh2000 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #include <set> 13 #include <string> 14 #include <stack> 15 using namespace std; 16 typedef long long LL; 17 const int MAXN = 50011; 18 const int MAXM = 200011; 19 int n,N,a[MAXN],maxl[MAXN]; 20 int cnt,prime[MAXM],ans; 21 bool vis[MAXM]; 22 23 inline int getint(){ 24 int w=0,q=0; char c=getchar(); while((c<‘0‘||c>‘9‘) && c!=‘-‘) c=getchar(); 25 if(c==‘-‘) q=1,c=getchar(); while (c>=‘0‘&&c<=‘9‘) w=w*10+c-‘0‘,c=getchar(); return q?-w:w; 26 } 27 28 inline void work(){ 29 n=getint(); for(int i=1;i<=n;i++) a[i]=getint(),N=max(a[i],N); ans=1; int x; 30 for(int i=2;i<=N;i++) { if(!vis[i]) prime[++cnt]=i; for(int j=1;j<=cnt && i*prime[j]<=N;j++) { vis[i*prime[j]]=1; if(i%prime[j]==0) break;} } 31 for(int i=1;i<=n;i++) { 32 x=a[i]; 33 for(int j=1;j<=cnt;j++) { 34 if(x%prime[j]!=0) continue; 35 maxl[i]=prime[j]; while(x%prime[j]==0) x/=prime[j]; 36 if(x==1) break; 37 } 38 } 39 for(int i=2;i<=n;i++) if(maxl[i]>maxl[ans]) ans=i; 40 printf("%d",a[ans]); 41 } 42 43 int main() 44 { 45 work(); 46 return 0; 47 }
标签:声明 appear typedef one class cal war number integer
原文地址:http://www.cnblogs.com/ljh2000-jump/p/6067648.html