比赛 防止浮躁的小练习v0.9 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 殉国 最终得分 100
用户昵称 ZXCVBNM_1 运行时间 0.057 s
代码语言 C++ 内存使用 0.26 MiB
提交时间 2016-11-07 18:41:27
显示代码纯文本
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
#include<set>
using namespace std;
#define LL long long
LL Gcd(LL aa,LL bb){if(bb==0LL)return aa;else return Gcd(bb,aa%bb);}
void Exgcd(LL aa,LL bb,LL &x,LL &y)
{
	if(bb==0LL){x=1;y=0;return;}
	Exgcd(bb,aa%bb,x,y);
	LL t=x;x=y;y=t-aa/bb*y;
}
int main()
{
	freopen("BlackHawk.in","r",stdin);
	freopen("BlackHawk.out","w",stdout);
	LL x=0,y=0,a,b,c,A,B,C,gcd,X1,Y1,X2,Y2;
	scanf("%lld %lld %lld",&a,&b,&c);
	if(a<b)swap(a,b);
	A=a;B=b;C=c;
	gcd=Gcd(a,b);
	if(c%gcd!=0){printf("-1 -1\n0");return 0;}
	a/=gcd;b/=gcd;c/=gcd;
	Exgcd(a,b,x,y);
	if(b<0)b=-b;
	X1=((x*c)%b+b)%b;Y1=(C-X1*A)/B;
	Y2=((y*c)%a+a)%a;X2=(C-Y2*B)/A;
	if(X1<0||Y1<0||X2<0||Y2<0){printf("-1 -1\n0");return 0;}
	printf("%lld %lld\n%lld",X2+Y2,X1+Y1,(X2-X1)/b+1LL);
	fclose(stdin);
	fclose(stdout);
	return 0;
}