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