fork(4) download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int rekurencja(int boka,int bokb)
  7. {
  8. unsigned long r;
  9. if(bokb==0) return (boka);
  10. else
  11. {
  12. r=boka%bokb;
  13. if (boka>bokb) boka=bokb;
  14. bokb=r;
  15. rekurencja (boka,bokb);
  16. }
  17. }
  18. int main()
  19. {
  20. int licznik;
  21. cin >> licznik;
  22. int a,b,c,pole;
  23. for (int i=0; i<licznik; i++)
  24. {
  25. cin >>a>>b;
  26. if (a==b)
  27. {
  28. int i=a-1;
  29. while (a%i!=0)
  30. {
  31. i--;
  32. }
  33. cout <<i <<endl;
  34. }
  35. else
  36. {
  37. pole =a*b;
  38. if (a>b) c=rekurencja(a,b);
  39. else
  40. c=rekurencja(b,a);
  41. cout <<c<<endl;
  42. }
  43. }
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 15240KB
stdin
2
2000 1000
10000 999983
stdout
1000
1