Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
0M 水过~~欧几里得模板水题#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator