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

0M 水过~~欧几里得模板水题

Posted by 13213824379 at 2017-11-30 21:01:30 on Problem 2115
#include<stdio.h>
typedef long long ll;
ll gcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll d=gcd(b,a%b,x,y);
	ll t=x;
	x=y;
	y=t-a/b*y;
	return d;
}
int main()
{
	ll A,B,C,K;
	ll x,y;
	while(scanf("%lld%lld%lld%lld",&A,&B,&C,&K)&&(A||B||C||K))
	{
		ll c=B-A;
	    ll a=C;
	    ll b=(ll)1<<K;
	    ll d=gcd(a,b,x,y);
		if(c%d)
		{
		printf("FOREVER\n");
		continue;
		} 
		ll s=b/d;
		ll min=(x*c/d%s+s) %s;
		printf("%lld\n",min);
	}
	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