Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cmath>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int fonction(int a, int b)
  10. {
  11. int total = 0;
  12. int i = 1;
  13. while (pow(a, i) < b)
  14. {
  15. total += b / pow(a, i);
  16. i++;
  17. }
  18. return total;
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24. int a;
  25. int b;
  26. cin >> a >> b; cin.ignore();
  27. int total = 0;
  28. vector<int> v;
  29. int c = a;
  30. int i = 2;
  31. while (c != 1)
  32. {
  33. if (c % i == 0)
  34. {
  35. c /= i;
  36. v.push_back(i);
  37. }
  38. else
  39. i++;
  40. }
  41. i = 0;
  42. int min = 100000;
  43. while (i < v.size())
  44. {
  45. int h = fonction(v[i], b) / count(v.begin(), v.end(), v[i]);
  46. if (h < max)
  47. max = h;
  48. i++;
  49. }
  50. cout << max << endl;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement