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:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, COB, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, kotlin, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, rust, SCALA, SCM chicken, SCM guile, SCM qobi, ST, swift, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.