标签:
for (variable = A; variable != B; variable += C)
statement;
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int INF=0x3f3f3f3f; typedef long long LL; void e_gcd(LL a,LL b,LL &d,LL &x,LL &y){ if(!b){ d=a; x=1; y=0; } else{ e_gcd(b,a%b,d,x,y); LL temp=x; x=y; y=temp-a/b*y; } } void cal(LL a,LL b,LL c){ LL d,x,y; e_gcd(a,b,d,x,y); if(c%d!=0){ puts("FOREVER"); return; } x*=c/d; b/=d; if(b<0)b=-b; x%=b; if(x<0)x+=b; printf("%I64d\n",x); return; } int main(){ LL A,B,C,k; while(~scanf("%lld%lld%lld%lld",&A,&B,&C,&k),A|B|C|k){ //C*x+2^ky=B-A; cal(C,(LL)1<<k,B-A); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4921950.html