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 hfbluehf at 2010-10-19 13:47:03 on Problem 1061
#include<iostream>
using namespace std;

long long Gcd(long long a,long long b,long long &x,long long &y){
	if(!b){
		x=1;
		y=0;
		return a;}
	long long x0,y0,c;
	c=Gcd(b,a%b,x0,y0);
	x=y0;
	y=x0-a/b*y0;
	return c;
}

int main(){
	long long x,y,m,n,l;
	while(cin>>x>>y>>m>>n>>l){
		long long w=x-y;
		w%=l;
		if(w*(m-n)>0){
			if(w<0)w=-w;
			w=l-w;}
		if(w<0) w=-w;
		long long w2=m-n;
		if(w2<0)w2=-w2;
		long long q1,c,q2;
		c=Gcd(w2,l,q1,q2);
		if(q1<0)q1+=l;
		if(q1>l)q1-=l;
		if(w%c){
			cout<<"Impossible\n";
			continue;}
		q1*=w/c;
		q1%=l;
		while(q1<0)q1+=l;
		while(q1>l)q1-=l;
		cout<<q1<<"\n";}
}

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