Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int CMMDC (int a, int b);
  5. int Verifica (int n);
  6.  
  7. int main()
  8. {
  9. int n, a, b, S, res;
  10. cin >> n;
  11.  
  12. for (int i = 1; i <= n; ++i)
  13. {
  14. cin >> a >> b;
  15. S = CMMDC (a, b);
  16. a /= S;
  17. b /= S;
  18. res = Verifica (b);
  19.  
  20. if (res == 0)
  21. cout << "fractie finita" << '\n';
  22. else if (res == 1)
  23. cout << "fractie periodica simpla" << '\n';
  24. else
  25. cout << "fractie periodica mixta" << '\n';
  26. }
  27.  
  28. return 0;
  29. }
  30.  
  31. int CMMDC (int a, int b)
  32. {
  33. int r;
  34. while (b != 0)
  35. {
  36. r = a % b;
  37. a = b;
  38. b = r;
  39. }
  40.  
  41. return a;
  42. }
  43.  
  44. int Verifica (int n)
  45. {
  46. bool DoiSauCinci = false;
  47. bool AltFactor = false;
  48. int d = 2;
  49.  
  50. while (n != 1)
  51. {
  52. while (n % d == 0)
  53. {
  54. if (d == 2 || d == 5)
  55. DoiSauCinci = true; // fractie finita
  56. else
  57. AltFactor = true; // fractie periodica simpla
  58.  
  59. n /= d;
  60. }
  61.  
  62. if (d == 2)
  63. d = 3;
  64. else
  65. d += 2;
  66.  
  67. if (d * d > n)
  68. d = n;
  69. }
  70.  
  71. if (DoiSauCinci && AltFactor)
  72. return 2; // fractie periodica mixta
  73.  
  74. if (AltFactor)
  75. return 1;
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement