because of symmetry, no one is different from others.
I used the same method and generalized by mathematical inductionā¦Wise minds
Well, apart from the for loop in main() I canāt actually see many differences on the other approachā¦ Even data types are correctā¦
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)
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.