fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <cstdint>
  4. #include <algorithm>
  5.  
  6. static const std::uint64_t Select = 22;
  7.  
  8. std::random_device rd;
  9. std::mt19937 mt(0);
  10. //std::mt19937 mt(rd());
  11. std::uniform_int_distribution<> uid(2, Select);
  12. std::uniform_int_distribution<> uid10n10(1, 1000000000);
  13.  
  14. std::uint64_t MakeHoge(std::uint64_t N){
  15. std::uint64_t Total = 0;
  16. std::uint64_t P = N;
  17. std::uint64_t S = 0;
  18. std::uint64_t D = 0;
  19.  
  20. do{
  21. D = uid(mt) - 1;
  22. S = Select % (D + 1);
  23.  
  24. if (S == (D + 1)){
  25. Total += P - P%D;
  26. P = P%D;
  27. }
  28. else{
  29. Total += (P / D) * std::max<std::int64_t>(0, S - 1);
  30. P = P / D;
  31. }
  32. } while (P > Select);
  33.  
  34. return Total + (Select % P);
  35.  
  36. }
  37.  
  38. int main(){
  39. std::uint64_t N = 0;
  40. std::uint64_t R = 0;
  41.  
  42. N = uid10n10(mt);
  43. R = MakeHoge(N);
  44. std::cout << N << " -> " << R <<"th"<< std::endl;
  45. N = uid10n10(mt);
  46. R = MakeHoge(N);
  47. std::cout << N << " -> " << R <<"th"<< std::endl;
  48. N = uid10n10(mt);
  49. R = MakeHoge(N);
  50. std::cout << N << " -> " << R <<"th"<< std::endl;
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
589284012 -> 329039759th
454895875 -> 209157241th
292762468 -> 59692260th