Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll compAns(int N, vi factors) {
- vi counts;
- int left = N;
- int curDig = 0;
- bool used = false;
- ll ans = 1;
- int added = 0;
- F0R(i, sz(factors)) {
- int nxt = left / factors[i];
- curDig++;
- counts.pb(left - nxt);
- left = nxt;
- }
- F0R(dig, sz(counts)) {
- int cur = counts[dig];
- ans = mul(ans, cur);
- cur--;
- F0R(i, cur) {
- ans = mul(ans, added + 1);
- added++;
- }
- added++;
- }
- return ans;
- }
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0);
- int N; cin >> N;
- ll total = 0;
- vi factors;
- int mulRes = 1;
- while (mulRes * 2 <= N) {
- factors.pb(2);
- mulRes *= 2;
- }
- total += compAns(N, factors);
- total = total % MOD;
- if (mulRes * 3 / 2 <= N) {
- factors.pop_back();
- factors.push_back(3);
- do {
- total += compAns(N, factors);
- total = total % MOD;
- } while (next_permutation(all(factors)));
- }
- cout << total << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment