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.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, 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, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.