标签:
for (variable = A; variable != B; variable += C) statement;
3 3 2 16 3 7 2 16 7 3 2 16 3 4 2 16 0 0 0 0
0 2 32766 FOREVER
#include<stdio.h> #define LL unsigned long long void exgcd(LL a,LL b,LL& d,LL& x,LL& y) { if(!b){d=a;x=1;y=0;} else { exgcd(b,a%b,d,y,x); y-=x*(a/b); } } int main() { LL A,B,C,k; while(scanf("%llu%llu%llu%llu",&A,&B,&C,&k),(A+B+C+k)) { LL a,b,c,d,x,y,dm; c=B-A; if(c==0){printf("0\n");continue;} a=C; b=(LL)1<<k; exgcd(a,b,d,x,y); if(c%d){ printf("FOREVER\n");continue;} dm=b/d; x=(((x*c/d)%dm)+dm)%dm; printf("%llu\n",x); } return 0; }
标签:
原文地址:http://www.cnblogs.com/yuyixingkong/p/4472312.html