7C Line

2019-04-13 20:46发布

class="markdown_views prism-atom-one-light"> 扩展欧几里德算法模板,虽然看了,博客还有小紫书,但是还是理解的很模糊,果然数学底子很差。。。后面在写感悟吧,再来补充。上传一张小紫书的欧几里德算法模板讲解这里写图片描述。这里还有别的博主详细的讲解传送门:http://blog.csdn.net/yanghui07216/article/details/49388143 C. Line time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from  - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. Input
The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0. Output
If the required point exists, output its coordinates, otherwise output -1. Examples
input
2 5 3
output
6 -3 #include #include #include #include using namespace std; typedef long long ll; void gcd(ll a,ll b,ll &d,ll &x,ll &y) { if(!b) { x=1; y=0; d=a; } else { gcd(b,a%b,d,y,x); y-=x*(a/b); } } int main() { ll a,b,c,x,y,d; while(cin>>a>>b>>c) { gcd(a,b,d,x,y); if(c%d!=0) puts("-1"); else cout<<-x*(c/d)<<' '<<-y*(c/d)<