Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. int fastpow(int x, int n, int m) {
  9. int res=1;
  10. if (!n) return 1;
  11. while (n) {
  12. if (n&1) {
  13. res=(res*x)%m;
  14. }
  15. x=(x*x)%m;
  16. n>>=1;
  17. }
  18. return res % m;
  19. }
  20.  
  21. void euclid(int a, int b, *int d, *int x, *int y) {
  22. int x1,x2,y1,y2,q,r;
  23. if (b==0) { *d=a; *x=1; *y=0; }
  24. while (b>0) {
  25. q=a/b;
  26. r=a-q*b;
  27. *x=x2-q*x1;
  28. *y=y2-q*y1;
  29. a=b;
  30. b=r;
  31. x2=x1;
  32. x1=*x;
  33. y2=y1;
  34. y1=*y;
  35. *d=a;
  36. *x=x2;
  37. *y=y2;
  38. }
  39.  
  40. }
  41.  
  42. int main() {
  43. int va,vb,d,x,y;
  44. cout<<"×èñëî à"<<endl;
  45. cin>>va;
  46. cout<<"×èñëî b"<<endl;
  47. cin>>vb;
  48. cout<<euclid(va,vb,d,x,y)<<endl;
  49. getch();
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement