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

大牛们帮忙看看我这怎么错的吧!

Posted by WhoMovedMyRP at 2006-03-08 14:25:18 on Problem 1061
#include <stdio.h>

__int64 e_gcd(__int64 a, __int64 b, __int64 *x, __int64 *y)
{
	__int64 x1, y1, p;
	if (b == 0)
	{
		*x = 1;
		*y = 0;
		return a;
	}

	p = e_gcd(b, a % b, &x1, &y1);

	*x = y1;
	*y = x1 - (a / b) * y1;
	return p;
}

__int64 abs(__int64 a)
{
	return (a > 0) ? a : -a;
}

int main()
{
	__int64 x, y, m, n, L;
	__int64 a, b, t, r, gcdans, lcmans, ans;

	while (scanf("%I64d %I64d %I64d %I64d %I64d", &x, &y, &m, &n, &L) != -1)
	{
		x %= L;
		y %= L;
		m %= L;
		n %= L;

		if (x > y)
		{
			a = x - y;
			b = (n - m + L) % L;
		}
		else
		{
			a = y - x;
			b = (m - n + L) % L;
		}
		
		gcdans = e_gcd(a, L, &t, &r);
		lcmans = a / gcdans * L;
		if (b % gcdans != 0)
		{
			printf("Impossible\n");
		}
		else
		{
			ans = (b / gcdans * t + lcmans) % lcmans;
			printf("%I64d\n", ans);
		}
	}
	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