Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

怎么超时了../?

Posted by zhan_ge at 2008-04-24 16:47:53 on Problem 1730
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator