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<iostream> using namespace std; inline int gcd(int a,int b) { int s; if(a<b) { s=a; a=b; b=s; } s=a%b; while(s!=0) { a=b; b=s; s=a%b; } return b; } int main(void) { register int i,n,j,G,num,G1,absj; bool first; while(scanf("%d",&n)==1&&n!=0) { j=n; G=1; first=true; absj=abs(j); for(i=2;i*i<=absj&&n!=0;i++) { num=0; if(n%i==0){ while(n%i==0) { num++; n=n/i; } if(first){ first=false; G1=G=num; } G=gcd(G,num); } } if(n<0&&G%2==0){ while(G%2==0&&G>=2) G=G/2; if(G==0) printf("1\n"); else printf("%d\n",G); } else if(n*n>absj) printf("1\n"); else printf("%d\n",G); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator