深圳幻海软件技术有限公司 欢迎您!

CodeForces - 7C

2023-03-30

C.Linetimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputAlineontheplaneisdescribedbyanequation Ax+By+C=0



C. Line
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 AB 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

思路:主要运用扩展欧几里得公式。


  1. #include<stdio.h>
  2. __int64 extgcd(__int64 a,__int64 b,__int64 &x,__int64 &y )
  3. {
  4. __int64 d=a;
  5. if(b!=0)
  6. {
  7. d=extgcd(b,a%b,y,x);
  8. y-=(a/b)*x;
  9. }
  10. else
  11. {
  12. x=1;
  13. y=0;
  14. }
  15. return d;
  16. }
  17. int main()
  18. {
  19. __int64 a,b,c,x,y;
  20. while(~scanf("%I64d %I64d %I64d",&a,&b,&c))
  21. {
  22. __int64 k=extgcd(a,b,x,y);
  23. if(c%k!=0)
  24. {
  25. printf("-1\n");
  26. }
  27. else printf("%I64d %I64d\n",x*(-c/k),y*(-c/k));
  28. }
  29. return 0;
  30. }