Combothermal

Untitled

Jun 3rd, 2019
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 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. }
Advertisement
Add Comment
Please, Sign In to add comment