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 |
WA到跪,求数据,用的是1LL<<k, 能过样例,还有讨论里给的数据,但是还是WA#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator