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

WA到跪,求数据,用的是1LL<<k, 能过样例,还有讨论里给的数据,但是还是WA

Posted by byijie at 2012-11-05 10:31:53 on Problem 2115 and last updated at 2012-11-05 10:35:36
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long A,B,C,K,x,y;
int ex_gcd(long long a,long long b)
{
    if(b==0)
    {
        x=1,y=0;
        return a;
    }
    else
    {
        int ans=ex_gcd(b,a%b);
        int t=x;
        x=y;
        y=t-a/b*y;
        return ans;
    }
}
void solve(long long a,long long b,long long n)
{
    x=y=0;
    long long gcd=ex_gcd(a,n);
    if(b%gcd!=0)
//        printf("FOREVER\n");
        cout<<"FOREVER"<<endl;
    else
    {
        x=(x*(b/gcd))%n;
        long long t=n/gcd;
        x=(x%t+t)%t;
//        printf("%ld\n",x);
        cout<<x<<endl;
    }
}
int main()
{
    long long D,a,b,n;
    while(cin>>A>>B>>C>>D)
    {
        if(A==0&&B==0&&C==0&&D==0)
            break;
        D=1LL<<K;
//        cout<<D<<endl;
        a=C,b=B-A,n=D;
//        cout<<n<<endl;
        solve(a,b,n);
    }
    return 0;
}   
        

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