ProveMeRight's blog

By ProveMeRight, history, 11 months ago, In English

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;

216404434

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.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
11 months ago, # |
  Vote: I like it 0 Vote: I do not like it
Updated Code
  • »
    »
    11 months ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    I tried to control this Negative Mod earlier too. But Still, It's not working.

    216406833

    • »
      »
      »
      11 months ago, # ^ |
        Vote: I like it +2 Vote: I do not like it

      You have taken wrong value of $$$mod$$$. Take $$$mod = 998244353$$$

      • »
        »
        »
        »
        11 months ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        Damn!! I'm so sorry.

        Thank you sooo much. I literally invested more than 4-5 hrs over it. :-'

»
11 months ago, # |
  Vote: I like it 0 Vote: I do not like it

skill issue