ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1204. Idempotents

Stefan Ciobaca Can someone explain this problem to me? [2] // Problem 1204. Idempotents 22 Mar 2002 03:41
I can have my program solve it in sqrt(n) but this is not good enough.
Please tell me how to optimize. 10x in advance
MadPsyentist/Sam Re: Can someone explain this problem to me? [1] // Problem 1204. Idempotents 22 Mar 2002 18:04
As I guess, your O(sqrt(n)) time is from finding ap+bq=1 , right?
If so , you can use extended Euclidean algorithm (one which find GCD)
to solve this equation.
Right! I got AC! (the GCD of p and q is 1!!!!!!!)