Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why wa

Posted by songxuehui at 2009-10-23 14:50:06 on Problem 2115
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator