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

Re:大家看看到底哪里错了的嘛 运行没错啊

Posted by mogen at 2010-04-10 10:55:00 on Problem 1061
In Reply To:大家看看到底哪里错了的嘛 运行没错啊 Posted by:mogen at 2010-04-10 10:49:44
> #include<iostream>
> using namespace std;
> class ModularLinearSolver//这个类解线性同余方程
> {
> private:
> 	long x,y,m,n,l;
> public:
> 	long ext_euclid(long a,long b,long &x,long &y);
> 	void modularSolver(long a, long b, long n);
> 	long mod(long a,long b);
> };
> 
> /******************************************** 
> 
>       求解模线性方程 ax=b (mod n) ,n>0 
> 
> *********************************************/ 
> void ModularLinearSolver::modularSolver(long a, long b, long n) 
> { 
>    long e,i,d; 
>    long x,y; 
>    d = ext_euclid(a, n, x, y); 
>    if (b%d==0) 
>    { 
> 	    e=(x*(b/d))%n;
>         cout<<mod(x*(b/d),n/d)<<endl;
>    }
>    else 
>    {  
>        cout<<"Impossible"<<endl; 
>    } 
> } 
> /********************************************* 
> 
>     扩展欧几里德算法求gcd(a,b)=ax+by 
> 
> *********************************************/ 
> long ModularLinearSolver::ext_euclid(long a,long b,long &x,long &y) 
> { 
>    long t,d; 
>    if (b==0)
>    {
> 	   x=1;y=0;return a;
>    } 
>    d=ext_euclid(b,a%b,x,y); 
>    t=x; 
>    x=y; 
>    y=t-a/b*y; 
>    return d; 
> } 
> long ModularLinearSolver::mod(long a,long b)
> {
> if(a >= 0)
>       return a % b;
> else
>       return a % b + b;
> }
> int main()
> {
> 	long x,y,m,n,l;
> 	ModularLinearSolver solver;
> 	cin>>x>>y>>m>>n>>l;
> 	solver.modularSolver(n-m,x-y,l);
>     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