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

1000组测试数据都过了还是WA,求解释

Posted by CNU2013 at 2014-04-13 06:23:30 on Problem 1061
#include<stdio.h>
#include<fstream>
#include<iostream>
#define swap(x,y) {w=x;x=y;y=w;}
using namespace std;
//ifstream fin("1061.in.txt");
int flag=1;
int doit(int a,int b,int c)
{
	int d=a,result;
	if(flag&&a){if(c%a)return (b*doit(b%a,d,(d-c)%d)+c)/a; else return c/a; } else{flag=0; return 0;}
	return 0;
}
int gcd(int a,int b)
{
	if(b&&a%b)return gcd(b,a%b);
	return b;
}
int main(){
	long long int w,top=0,ans,x,y,m,n,l,a,b,c,d,gml,gnl,gmnl;
	while(cin>>x>>y>>m>>n>>l)
	{
		
	  if(m<n){swap(m,n);swap(x,y);}
	  gml=l/gcd(m,l);gnl=l/gcd(n,l); gmnl=gml*gnl/gcd(gml,gnl);
	  a=m-n;b=l;c=y-x;
	  flag=1;ans=(doit(a,b,c)+l)%l%gmnl; if(flag)cout<<(ans-1)%l+1<<endl; else printf("Impossible\n");
	 
    }
	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