When I use the normal iterative to compute the chebyshev and fermat’s little theorem for modular inverse,
I get wrong answer on the first subtask.
The given test cases are computed right tho, and yes, I need something better for when t is large
but could someone tell me what’s wrong in this code, at least for t <= 3?
@albert it is possible that multiplying the two values may result in integer overflow. Hence after multiplying two values take mod, and then multiply with third value.
It is written in French but I guess you should be able to understand the basic idea by reading the equation.
So look for chapter: “Suite récurrente d’ordre p” on page: Suite récurrente linéaire — Wikipédia
NB: I did not find the same explanation in English.
you wont get ans in p/q form, even if u try to use fractions in python, you’ll have to round your cos(tx), in this case you’ll get wrong ans because precision will be different.
@siddharthp538 why not do mod 360 or 2*PI depending whether you are using degrees or radians, and then t will be a very small value and precision will be saved right ?
Actually this happened with me during the contest, i was getting cos(60) as 0.4999999999999999 and using Fraction if u convert it in p/q form then p comes as 4503599627370495 and q comes as 9007199254740992. p*(q^-1) comes out to be 879237148. It makes a huge diff to our ans. Actually if u do mod 360 still values will be rounded. It can give us wa.