您的位置:首页 > 其它

CodeForces 7C Line (扩展欧几里得)

2015-04-02 22:33 337 查看
前面忘记修改gcd,一直求不出来。。。套套模板轻松水,,

#include "string"
#include "iostream"
#include "cstdio"
#include "cmath"
#include "set"
#include "queue"
#include "vector"
#include "cctype"
#include "sstream"
#include "cstdlib"
#include "cstring"
#include "stack"
#include "ctime"
#include "algorithm"
#define pa pair<int,int>
#define Pi M_PI
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long LL;
const int M=55;

LL x,y;

LL exgcd(LL a,LL b)
{
LL t,d;
if(b==0)
{
x=1;
y=0;
return a;
}

d=exgcd(b,a%b);
t=x;
x=y;
y=t-(a/b)*y;

return d;
}

int main()
{
LL a,b,c,d;
while(cin>>a>>b>>c)
{
if(exgcd(a,b)!=1)
cout<<-1<<endl;
else
{
x=-x*(c/d);
y=-y*(c/d);
cout<<x<<' '<<y<<endl;

}
}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: