fork(2) download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int calcZ(int px, long long D){
  6. int res = 0;
  7. while (px){
  8. res+=px;
  9. px/=D;
  10. }
  11. return res;
  12. }
  13.  
  14. long long calc(map<long long,int> factor){
  15. long long ans = 0;
  16. for (auto x : factor){
  17. auto value = x.first;
  18. auto degree= x.second;
  19. int curD = 1;
  20. while (calcZ(curD,value) < degree)
  21. curD++;
  22. ans = max(ans,curD*value);
  23. }
  24. return ans;
  25. }
  26.  
  27. int main() {
  28. // your code goes here
  29. map<long long,int> m;
  30. m[2] = 2;
  31. cout << calc (m)<<endl;// (4)
  32. m[2] = 3;
  33. cout << calc (m)<<endl;// (8)
  34. m[3] = 2;
  35. cout << calc (m)<<endl;// (72)
  36. m[3] = 0;
  37. m[2] = 20;
  38. cout << calc (m)<<endl;// (2^20)
  39. m[2] = 3;
  40. m[3] = 1;
  41. m[5] = 1;
  42. cout << calc (m)<<endl;// 120
  43. m[2] = 0;
  44. m[3] = 3;
  45. m[5] = 1;
  46. m[7] = 1;
  47. cout << calc (m)<<endl;// 945
  48. return 0;
  49. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
4
4
6
24
5
9