hopingsteam

Subiectul 3 -> Problema 1

Apr 7th, 2021
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // 16500 = 2^2 * 3^1 * 5^3 * 11^1
  6. int baza_n[15]; // [0] -> 2 [1] -> 3 [2] -> 5
  7. int putere_n[15]; // [0] -> 2 [1] -> 1 [2] -> 3
  8.  
  9. int baza_m[15];
  10. int putere_m[15];
  11.  
  12. int factori(unsigned int n, unsigned int m)
  13. {
  14. int div = 2, putere = 0, total_n = 0, total_m = 0, rezultat = 0;
  15. while(n > 1)
  16. {
  17. if(n % div == 0)
  18. {
  19. putere = 0;
  20. while(n % div == 0)
  21. {
  22. putere = putere + 1;
  23. n = n / div;
  24. }
  25. baza_n[total_n] = div;
  26. putere_n[total_n] = putere;
  27. total_n = total_n + 1;
  28. }
  29. div = div + 1;
  30. }
  31. div = 2, putere = 0;
  32. while(m > 1)
  33. {
  34. if(m % div == 0)
  35. {
  36. putere = 0;
  37. while(m % div == 0)
  38. {
  39. putere = putere + 1;
  40. m = m / div;
  41. }
  42. baza_m[total_m] = div;
  43. putere_m[total_m] = putere;
  44. total_m = total_m + 1;
  45. }
  46. div = div + 1;
  47. }
  48.  
  49. for(int i = 0; i < total_n; i++)
  50. {
  51. for(int j = 0; j < total_n; j++)
  52. {
  53. if(baza_n[i] == baza_m[j] && putere_n[i] == putere_m[j])
  54. rezultat++;
  55. }
  56. }
  57. return rezultat;
  58. }
  59.  
  60. int main()
  61. {
  62. cout << factori(16500, 10780);
  63. return 0;
  64. }
RAW Paste Data