FCBARCA - Editorial

because of symmetry, no one is different from others.

I used the same method and generalized by mathematical inductionā€¦Wise minds :stuck_out_tongue:

1 Like

Well, apart from the for loop in main() I canā€™t actually see many differences on the other approachā€¦ Even data types are correctā€¦ :frowning:

Yes u are correct, in AC sol.n i didnā€™t called that powmod() so neglect it. I instead used a simpler version of calculating polynomials like this ax^n + bx^n-1ā€¦O(n).

I am just asking why did the above approach of simply calculating first ax^n then bx^n-1 upto last term didnā€™t worked out(I know the error is in powmod())ā€¦I feel strongly that itā€™s correctā€¦I just want the flaw in itā€¦
Thanks.

@xpertcoder Your powermod is very correct.

But, you get WA because, you have some subtractions in your code, and subtractions in modular arithmetic doesnā€™t just work the way you coded.

In modular arithmetic (say, modulo n), actual negative numbers also become positive under the modulo. So, -k will be represented as n-k.

I added that change to your code, and voila!!

There are two positions in your code, to add that check and I have done both. Have a look: http://www.codechef.com/viewplaintext/2056117 and http://www.codechef.com/viewplaintext/2056109 (Both are AC solutions)

2 Likes

OMG!!! Thatā€™s it.I didnā€™t knew thatā€¦All I know was whenever you get (a-b)%m all you do is ((a%m)-(b%m))%m. I left that case of yours.Now I am gonna remember that for a very long tym. THANKS A LOT. :slight_smile:

1 Like