Блог пользователя saurabh247

Автор saurabh247, история, 5 лет назад, По-английски

Problem link https://codeforces.me/contest/615/problem/D

My Submission https://codeforces.me/contest/615/submission/78009885

Can anyone please tell why my submission is getting WA . I have read the editorial and got the solution but i would like to know why this approach is not working. I am trying this for a long time and have no clue. Please help!!

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by saurabh247 (previous revision, new revision, compare).

»
5 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Look at comments : https://codeforces.me/blog/entry/22658?#comment-271616 and https://codeforces.me/blog/entry/22658?#comment-271626.

you are calculating power(p, k) under modulo 1e9+7 (M). However while calculating k you are taking k = k%M. Instead you have to take k%(M-1) due to fermat's theroem.

For calculating, $$$P = ((cnt[1]+1)*(cnt[2]+1)*(cnt[3]+1)*....*(cnt[k]+1)) * (cnt[i]+1)^{-1} mod (M-1)$$$ , you can precompute : $$$lmul[i] = (cnt[1]+1)*(cnt[2]+1)*(cnt[3]+1)*....*(cnt[i]+1)$$$ $$$rmul[i] = (cnt[i]+1)*(cnt[i+1]+1)*(cnt[i+2]+1)*....*(cnt[k]+1)$$$

Now, $$$P = lmul[i-1] * rmul[i+1]$$$

Now your $$$k = P*((cnt[i]*(cnt[i]+1))/2)mod(M-1)$$$

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thnx but I still have a query .. As you said that for calculating k i have to take mod with (M — 1). I took mod with (M — 1) with my previous submission and got again WA My submission https://codeforces.me/contest/615/submission/78094420 .. I want to know why this is happening ? could u pls help

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      You are finding inverse of 2 mod (M-1). However it will not exist. Calculate k like this : $$$k=P∗((cnt[i]∗(cnt[i]+1))/2)mod(M−1)$$$

      Here before diving by 2, the numerator will be even. So mod (M-1) can be found after dividing by 2.