Combothermal

Untitled

Jun 3rd, 2019
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. ll compAns(int N, vi factors) {
  2. vi counts;
  3. int left = N;
  4. int curDig = 0;
  5. bool used = false;
  6. ll ans = 1;
  7. int added = 0;
  8. F0R(i, sz(factors)) {
  9. int nxt = left / factors[i];
  10. curDig++;
  11. counts.pb(left - nxt);
  12. left = nxt;
  13. }
  14.  
  15. F0R(dig, sz(counts)) {
  16. int cur = counts[dig];
  17. ans = mul(ans, cur);
  18. cur--;
  19. F0R(i, cur) {
  20. ans = mul(ans, added + 1);
  21. added++;
  22. }
  23. added++;
  24. }
  25. return ans;
  26.  
  27. }
  28.  
  29. int main() {
  30. ios_base::sync_with_stdio(0); cin.tie(0);
  31.  
  32. int N; cin >> N;
  33. ll total = 0;
  34. vi factors;
  35. int mulRes = 1;
  36. while (mulRes * 2 <= N) {
  37. factors.pb(2);
  38. mulRes *= 2;
  39. }
  40.  
  41. total += compAns(N, factors);
  42. total = total % MOD;
  43.  
  44. if (mulRes * 3 / 2 <= N) {
  45. factors.pop_back();
  46. factors.push_back(3);
  47. do {
  48. total += compAns(N, factors);
  49. total = total % MOD;
  50. } while (next_permutation(all(factors)));
  51. }
  52.  
  53.  
  54.  
  55. cout << total << endl;
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment