Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int CMMDC (int a, int b);
- int Verifica (int n);
- int main()
- {
- int n, a, b, S, res;
- cin >> n;
- for (int i = 1; i <= n; ++i)
- {
- cin >> a >> b;
- S = CMMDC (a, b);
- a /= S;
- b /= S;
- res = Verifica (b);
- if (res == 0)
- cout << "fractie finita" << '\n';
- else if (res == 1)
- cout << "fractie periodica simpla" << '\n';
- else
- cout << "fractie periodica mixta" << '\n';
- }
- return 0;
- }
- int CMMDC (int a, int b)
- {
- int r;
- while (b != 0)
- {
- r = a % b;
- a = b;
- b = r;
- }
- return a;
- }
- int Verifica (int n)
- {
- bool DoiSauCinci = false;
- bool AltFactor = false;
- int d = 2;
- while (n != 1)
- {
- while (n % d == 0)
- {
- if (d == 2 || d == 5)
- DoiSauCinci = true; // fractie finita
- else
- AltFactor = true; // fractie periodica simpla
- n /= d;
- }
- if (d == 2)
- d = 3;
- else
- d += 2;
- if (d * d > n)
- d = n;
- }
- if (DoiSauCinci && AltFactor)
- return 2; // fractie periodica mixta
- if (AltFactor)
- return 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement