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

为什么会WA啊???????

Posted by killed at 2010-07-11 15:30:52 on Problem 1061
#include<iostream>
#include<stdio.h>
using namespace std;
int gcd(int a,int b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex_eulid(int a,int b,int &m,int &n)
{    
    if(b==0)
    {
         m=1;
         n=0;
         return;
    }
    ex_eulid(b,a%b,m,n);
    int t;
    t=m;
    m=n;
    n=t-a/b*n;   
}
int main()
{
 int x,y,m,n,l,a,b,c,r,j1=0,j2=0,t;
 while(scanf("%d%d%d%d%d",&x,&y,&m,&n,&l)!=EOF)
 {
    a=n-m;
    b=l;
    c=x-y;
    r=gcd(a,b);
    if(c%r)
    {
       printf("%s\n","Impossible");
       continue;       
    }
    a/=r;
    b/=r;
    c/=r;
    //cout<<a<<b<<c<<endl;
    ex_eulid(a,b,j1,j2);
    t=c*j1/b;
    j1=c*j1-t*b;
    if(j1<0)
    {
       if(b>0)j1+=b;
       else j1-=b;
    }
    printf("%d\n",j1);                                              
 }   
 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