| ||||||||||
| 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 | |||||||||
why wa#include <cstdio>
long long ex_gcd(long long a,long long b,long long &x,long long &y){
long long t ,d ;
if(b==0) { x = 1 ; y = 0; return a;}
d = ex_gcd (b,a%b,x,y);
t = x , x = y,y = t - a/b*y;
return d;
}
int main()
{
long long a,b,c,n,x,y,d;
int k;
while(scanf("%lld%lld%lld%d",&a,&b,&c,&k),a||b||c||k){
n = 1;
n = n <<k;
if(b>=a) b = b - a;
else b = n- a + b;
d = ex_gcd(c,n,x,y);
if(b%d>0) printf("FOREVER\n");
else printf("%lld\n",x*b/d%n);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator