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 VID at 2013-12-26 14:30:07 on Problem 2115
#include<iostream>
using namespace std;

__int64 exgcd(__int64 a,__int64 b,__int64 &x,__int64 &y)
{
	if(0==b){
		x=1;
		y=0;
		return a;
	}
	__int64 d = exgcd(b,a%b,x,y);
	__int64 temp = x;
	 x = y; y = temp - a / b * y;
	return d;
}

int main(void)
{
	__int64 A, B, C, k;
	while(scanf("%I64d %I64d %I64d %I64d",&A,&B,&C,&k))
	{
		if(!A && !B && !C && !k)
		    break;
          __int64 a=C;
          __int64 b=B - A;
          __int64 n=(__int64)1<<k;//计算n=2^k时,用位运算是最快的,1<<k (1左移k位)就是2^k,使用long long的要注意格式, 1LL<<k;使用__int64的要强制类型转换 (__int64)1<<k
          __int64 x,y;
		__int64 d=exgcd(a,n,x,y);
		if(b % d != 0)
		{
			cout<<"FOREVER"<<endl;
		}
		else
		{
			x=(x*(b/d))%n;//方程ax=b(mod n)的最小解  
			//此时只是求得了同余方程的最小解不一定是整数解,所以下面的操作就是求得该方程的最小整数解! 
			if(x < 0)
			{
				x += n/d;
			}
			cout<<x<<endl;
		}
	}
	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