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 li4951 at 2009-04-28 22:26:22 on Problem 2115
#include<iostream>
#include<cmath>
using namespace std;

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

int main()
{
	__int64 A = 0;
	__int64 B = 0;
	__int64 C = 0;
	int k = 0;
//	freopen("2115.txt", "r", stdin);
	while(scanf("%I64d%I64d%I64d%d", &A, &B, &C, &k) && ((A != 0) || (B != 0) || (C != 0) || (k != 0)))
	{
		__int64 a = C;
		__int64 b = 1;
		b = 1 << k;
		__int64 c = B - A;
	
		__int64 x = 0;
		__int64 y = 0;
		__int64 gcd = exgcd(a, b, x, y);
		if(c % gcd != 0)
		{
			cout << "FOREVER" << endl;
		}
		else
		{
			a /= gcd;
			b /= gcd;
			c /= gcd;
			gcd = exgcd(a, b, x, y);
			x = x * c;
			printf("%I64d\n", (x % (b) + (b)) % (b));
		}
	}
	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