标签:ted ant amp exgcd plm ble mina repeat asi
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 24380 | Accepted: 6793 |
Description
for (variable = A; variable != B; variable += C)
statement;
Input
Output
Sample Input
3 3 2 16 3 7 2 16 7 3 2 16 3 4 2 16 0 0 0 0
Sample Output
0 2 32766 FOREVER
Source
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 typedef long long LL; 5 LL A,B,C,k; 6 LL a,b,c,d,e,f,x,y; 7 LL exgcd(LL a,LL b,LL &x,LL &y){ 8 if (b==0) 9 {x=1; 10 y=0; 11 return a; 12 } 13 LL d=exgcd(b,a%b,x,y); 14 LL t=x; 15 x=y; 16 y=t-(a/b)*y; 17 return d; 18 } 19 int main(){ 20 freopen ("c.in","r",stdin); 21 freopen ("c.out","w",stdout); 22 int i,j; 23 while (1) 24 {scanf("%lld%lld%lld%lld",&A,&B,&C,&k); 25 if (A==0 && B==0 && C==0 && k==0) 26 break; 27 a=C,b=1ll<<k,c=B-A; 28 d=exgcd(a,b,x,y); 29 if (c==0) 30 {puts("0"); 31 continue; 32 } 33 if (c%d!=0) 34 {puts("FOREVER"); 35 continue; 36 } 37 e=x*(c/d); 38 f=(e%(b/d)+b/d)%(b/d); 39 printf("%lld\n",f); 40 } 41 return 0; 42 }
标签:ted ant amp exgcd plm ble mina repeat asi
原文地址:http://www.cnblogs.com/keximeiruguo/p/5990319.html