标签:else can ++ abs cpp its using scan std
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b) {return b?gcd(b,a%b):a;}
int exgcd(int &x,int &y,int a,int b)
{
if(!b)
{
x=1;
y=0;
return a;
}
int r=exgcd(x,y,b,a%b);
int t=x;
x=y;
y=t-a/b*y;
return r;
}
bool cal(int &x,int &y,int a,int b,int c)
{
int d=exgcd(x,y,a,b);
if(c%d) return false;
int k=c/d;
x*=k;
y*=k;
return true;
}
int main()
{
int x,y,a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(cal(x,y,a,b,c))
{
printf("%d %d\n",x,y);//输出任意解
int tx=x;
x%=b;
if(x<=0) x+=(int)abs(b*1.0);
int k=(tx-x)/b;
y += k*a;
printf("%d %d\n",x,y);//输出最小正整数解
}
else puts("No answer!");//无解
return 0;
}
标签:else can ++ abs cpp its using scan std
原文地址:https://www.cnblogs.com/juruo-zzt/p/11910628.html