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.
val = (fact[n] * inv(cnt+1))%mod
cout << (fact[n] — val + mod) % mod << endl;
I tried to control this Negative Mod earlier too. But Still, It's not working.
216406833
You have taken wrong value of $$$mod$$$. Take $$$mod = 998244353$$$
Damn!! I'm so sorry.
Thank you sooo much. I literally invested more than 4-5 hrs over it. :-'