Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // 16500 = 2^2 * 3^1 * 5^3 * 11^1
- int baza_n[15]; // [0] -> 2 [1] -> 3 [2] -> 5
- int putere_n[15]; // [0] -> 2 [1] -> 1 [2] -> 3
- int baza_m[15];
- int putere_m[15];
- int factori(unsigned int n, unsigned int m)
- {
- int div = 2, putere = 0, total_n = 0, total_m = 0, rezultat = 0;
- while(n > 1)
- {
- if(n % div == 0)
- {
- putere = 0;
- while(n % div == 0)
- {
- putere = putere + 1;
- n = n / div;
- }
- baza_n[total_n] = div;
- putere_n[total_n] = putere;
- total_n = total_n + 1;
- }
- div = div + 1;
- }
- div = 2, putere = 0;
- while(m > 1)
- {
- if(m % div == 0)
- {
- putere = 0;
- while(m % div == 0)
- {
- putere = putere + 1;
- m = m / div;
- }
- baza_m[total_m] = div;
- putere_m[total_m] = putere;
- total_m = total_m + 1;
- }
- div = div + 1;
- }
- for(int i = 0; i < total_n; i++)
- {
- for(int j = 0; j < total_n; j++)
- {
- if(baza_n[i] == baza_m[j] && putere_n[i] == putere_m[j])
- rezultat++;
- }
- }
- return rezultat;
- }
- int main()
- {
- cout << factori(16500, 10780);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement