CF 7C. Line(扩展欧几里德)

题目链接

AC了。经典问题,a*x+b*y+c = 0整数点,有些忘记了扩展欧几里德,复习一下。

 1 #include <cstdio>

 2 #include <iostream>

 3 #include <cmath>

 4 using namespace std ;

 5 #define LL __int64

 6 LL x,y;

 7 LL ext_eulid(LL a,LL b)

 8 {

 9     LL t,d;

10     if(b == 0)

11     {

12         x = 1;

13         y = 0;

14         return a;

15     }

16     d = ext_eulid(b,a%b);

17     t = x;

18     x = y;

19     y = t - (a/b)*y;

20     return d;

21 }

22 int main()

23 {

24     LL A,B,C,d;

25     cin>>A>>B>>C;

26     d = ext_eulid(A,B);

27     if((-C)%d != 0)

28     {

29         printf("-1\n");

30     }

31     else

32     {

33         x = x*((-C)/d);

34         y = y*((-C)/d);

35         cout<<x<<" "<<y<<endl;

36     }

37     return 0;

38 }

 

你可能感兴趣的:(in)