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

1061怎么在162.105.31.253上面过了,在pku过不了,大家帮帮忙

Posted by _Magician_ at 2009-07-13 12:11:28 on Problem 1061
#include<iostream>
using namespace std;
long long   gac(long long   a1,long long   b1)
{
	
if((a1%b1)==0)
{
  return b1;
}
else
{
long long   c=a1;
a1=b1;
b1=c%b1;
return gac(a1,b1);

}
}
long long   f(long long   a,long long   b,long long   c)
{
	if(c==0)
	{
		return b/gac(b,a);
	}
	if(a==1)
		return c;
	long long  kk=gac(b,a);
	if(c%kk!=0)
		return 0;
	else
	{
		if(b%a==0)
		{
			return (c/a);
		}
    long long   b1=b%a;
	long long   d=(b-c)%a;
	long long   re=f(b1,a,d)-1;
	if(re==-1)
		return 0;
	long long   k=(re*b+c)/a;
	k=k%(b/((gac(b,a))));
	return k;
	}
}
       
int  main()
{
 
  
  
    long long  x,y,m,n,L;

    while(cin>>x>>y>>m>>n>>L)
	{
    if(x<0)
    {
           x=x%L+L;
           }
           else
           {
               x=x%L;
           }
           if(y<0)
           {
           y=y%L+L;
           }
           else
           {
            y=y%L;
            }
           if(x==y)
           {
                   cout<<0<<endl;
                   
                   continue ;
                   }
                 //x!=y  
                  
                
                  long long  s;
                  long long  a;
                  long long  b;
                  if(m==n)
                  {
                  cout<<"Impossible";
                  
                  continue ;
                  }
                  //以下的讨论都是(x!=y&&m!=n) 
P1:
           if(m>n)
           {
                  long long  d1=m-n;
                  long long  d2=y-x;
                  long long  g=L%d1;
                  if(g==0)
                  {
                          if((d2%d1)!=0)
                          {
                          
                                   cout<<"Impossible";
                                   
                                   continue ;
                                   }
                  else
                  {
                      if(d2>0)
                      {
                              cout<<d2/d1;
                             
                             continue ;

                              }
                              else
                              {
                                  cout<<(d2+L)/d1;
                                  
                                  continue ;
                              }
                  }
                                  
                                   }
                  else
                  {
P:
                      if(d2>0)
                      {
                              long long  ys=d2%d1;
                              if(ys==0)
                              {
                                       cout<<d2/d1;
                                       
                                       continue ;
                              }
                              else
                              {
                                  long long  ys1=d1-ys;
                                  long long  k=f(L%d1,d1,ys1);
								  if(k==0)
								  {
									  cout<<"Impossile"<<endl;
									  
									  continue ;
								  }
                                  long long  m=d1/gac(L,d1);
                                  k=k%m;
								  if(k==0)
								  {
									  k=m;
									   cout<<(d2+k*L)/d1;
                                  //注意点; 
                                  continue ;
								  }
									  
                                 
                                  cout<<(d2+k*L)/d1;
                                  //注意点; 
                                  continue ;
                                  
                              }
                              
					  }
				  
                      else
                      {
						     
                              long long  ys=(d2%d1);
							  
                             
                             
                              {
                                  
                                  long long  k=f(L%d1,d1,-ys);
								  if(k==0)
								  {
									  cout<<"Impossile"<<endl;
									  
									  continue ;
								  }
                                  long long  m=d1/gac(L,d1);

                                  k=k%m;
								  if(k==0)
								  {
									  k=m;
									  cout<<(d2+k*L)/d1;
                                  //注意点; 
                                  continue ;

								  }
                                
                                  cout<<(d2+k*L)/d1;
                                  //注意点; 
                                  continue ;
                          
                                  
                              }
                                                                                                                                                                                                                                          
                      }
                              
                      
                 
                        
                  
				  }
                  
				  }
           else
           {
               long long  temp1,temp2;
               temp1=m;
               m=n;
               n=temp1;
               temp2=y;
               y=x;
               x=temp2;
               goto P1;
               
               
               
           }
		   }
		   
		   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