According to the solution, I need to calculate n! — (n!/(k+1).
I tried two ideas to calculate this but still got the wrong answer on Test 2
216215234 for the idea:
val = (fact[n] * inv(cnt+1))%mod
cout << fact[n] - val << endl;
int val = fact[n]/(cnt+1);
cout << fact[n] - val << endl;
Please help, as I'm stuck on this since yesterday.
void solve() {
int n;
cin >> n;
vi v(n);
rep(i, 0, n) cin >> v[i];
sort(all(v));
if (v[n - 1] == v[n - 2])
{
cout << fact[n] << endl;
return;
}
int cnt = count(all(v),v[n-1]-1);
int val = (fact[n] * inv(cnt+1))%mod
cout << fact[n] - val << endl;
}
Note: In my template, I defined int as a long long, and pre-computed fact array.