All submissions for this problem are available.
Professor X got lost in a maze of an ancient tomb in Egypt. While he was finding the way to escape, he got a message of the tomb builders on the old walls:
- The code to open the exit door is the sequence C of n digits formed c1..cn (ci∈[0,9] ).
- For every sequence C, combining with the given integers A,B, call:
- hi=(hi-1×A+ci) mod B
- The smallest sequence C (in lexicological order) satisfying hn=G (where G is a given integer) is the exit code which professor X needs.
Give the integers n,A,B,G, help professor X find out the exit code!
One and only line contains the integers n,A,B,G, respectively, each of them is separated with at least one space character.
Output in a single line the exit code found.
3 11 111 92
- The input satisfies that the answer always exist.
|Tags||anhdq, aug10, medium|
|Time Limit:||0.677106 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.