Advertisement
Luca_Codorean

Untitled

Nov 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3. #include <cmath>
  4. using namespace std;
  5. int cmmdc (int a, int b)
  6. {
  7. int r,d,i;
  8. d=a;
  9. i=b;
  10. while (i>0)
  11. {
  12. r=d%i;
  13. d=i;
  14. i=r;
  15. }
  16. return d;
  17. }
  18. /**int nrdiv (int x)
  19. {
  20.  
  21. {
  22. int nrd=1;
  23. int p=0,d=2;
  24. while (x%d==0)
  25. {
  26. p++;
  27. x/=d;
  28. }
  29. if (p>0)
  30. {
  31. nrd*=(p+1);
  32. }
  33. d=3;
  34. while (x>1)
  35. {
  36. p=0;
  37. while (x%d==0)
  38. {
  39. x/=d;
  40. p++;
  41.  
  42. }
  43. if (p)
  44. {
  45. nrd*=(p+1);
  46. }
  47. if (d*d<x)
  48. {
  49. d=d+2;
  50.  
  51. }
  52. else
  53. {
  54. d=x;
  55. }
  56. }
  57. return nrd;
  58. }
  59. }*/
  60. int main ()
  61. {
  62. int n,i,a,b,r,c;
  63. int minim=INT_MAX;
  64. int maxim=INT_MIN;
  65. cin>>n;
  66. for (i=1; i<=n; i++)
  67. {
  68. cin>>a>>b;
  69. c=cmmdc(a,b);
  70. r=sqrt(c);
  71. if (c<minim && r*r!=c)
  72. {
  73. minim=c;
  74. }
  75. if (c>maxim && r*r==c)
  76. {
  77. maxim=c;
  78. }
  79. }
  80. if (minim==INT_MAX || maxim==INT_MIN)
  81. {
  82. cout<<"NU EXISTA";
  83. return 0;
  84. }
  85. cout<<minim<<" "<<maxim;
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement