Exit codeProblem code: ECODE |
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:
- h0=0
- 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.
- 1≤n≤12
- 10≤A,B≤1015
- 0≤G<B
- The input satisfies that the answer always exist.
Request
Give the integers n,A,B,G, help professor X find out the exit code!Input
One and only line contains the integers n,A,B,G, respectively, each of them is separated with at least one space character.
Output
Output in a single line the exit code found.
Example
Input:3 11 111 92Output:
084
Limitations
| Author: | anhdq |
| Date Added: | 5-05-2010 |
| Time Limit: | 6 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments

Fetching successful submissions

hi=h(i-1)A+... Does this
hi=h(i-1)A+...
Does this imply that we have to take the product of h(i-1)and A?
@Vijay Kansal: yes, "x" means
@Vijay Kansal: yes, "x" means producting!
should i specify inside the
You may take it for granted
You may take it for granted that the input will respect the given limitations. You don't have to check for them. Your program is only expected to run (and produce correct output) if the input is within the limits.
@Admin: there is a typo in
@Admin: there is a typo in the Limitations section on the upper limit of A and B.
What is the time limit?
What is the time limit?
@all: there is some errors
@all: there is some errors with the Limitations part, please follow the limitations mentioned just below the sentence "...the exit code which professor X needs".
The timelimit is 6s, we will try to display it correctly!
In limitations, 10<=A,B<=1015
In limitations, 10<=A,B<=1015 should be 10<=A,B<=1015 .
I think I'm a little confused
I think I'm a little confused between the mathematical mod and the % operator:
when you say a = c mod b, do you mean
1) a = c % b;
2) a mod b = c mod b (as in a is equivalent to c modulo b)
?
what's the time limit ?
what's the time limit ?
is there exist more than 1
is there exist more than 1 possible answer if yes then which should we have to priint.....??
are A and B of the form
are A and B of the form 10^i??
sorry !! got it
sorry !! got it
@Amritipal - by definition of
@Amritipal - by definition of 'smallest' the answer must be unique.
what is lexicological order??
what is lexicological order??
@vijay hit google.......
@vijay
hit google.......
is there a blank line after
is there a blank line after the output.....??? plz rply....
Could you please answer the
Could you please answer the question about time limit?
@Keghani Kouzoujian: mod
@Keghani Kouzoujian: mod means %, I think it's ok because mod is an operator in Pascal as % is an operator in C/C++ :-)
@forest, Przemyslaw Derengowski: already answered, please check.
is all hi for 12 digit can
is all hi for 12 digit can hold inside int
if a and B are very large.
@AMRITPAL SINGH: yes @atul:
@AMRITPAL SINGH: yes
@atul: no comment ;-)
What if A and B have numbers
What if A and B have numbers with leading zeros, for example
n=12
A=1000
B=200
G=190
what will be the output of sequence C?
will it tally the condition h[n]=G??
I don't know what you are
I don't know what you are talking about when you say leading zeroes, but perhaps you are asking something that is answered by this sentence in the problem: "The input satisfies that the answer always exist.".
@Kaushik N. Sanji: anything
@Kaushik N. Sanji: anything not a "code" must be used like a "number"
can you give some more test
can you give some more test cases.
@Stephen Merriman Sorry for
@Stephen Merriman
Sorry for stating leading zeros, I actually wanted to say trailing zeros (for A and B) as in the case of the example
n=12
A=1000
B=200
G=190
I just wanted to know whether you actually got this condition h[n]=G for the above values of n, A, B, G
Thanks for the reply
is lexological means that
is lexological means that number should smallest while moving from left to right.... Am i right....???
what is the time limit?
what is the time limit?
This is lexicographical
This is lexicographical order, I also wonder what is lexicological order?
@all: Time Limit is 6s as I
@all: Time Limit is 6s as I replied above, please read first before question anything :-)
about the lexicological order, it is a term I think everyone can know :-) just hit Google for detail :-)
@AnhDQ: As mentioned in the
@AnhDQ: As mentioned in the comment above yours, I think you meant lexicographical order, not lexicological order.
someone please explain the
someone please explain the meaning of lexicographical order. I googled it but still not able to understand. What is its use in context of this problem?
@Stephen Merriman: doesn't it
@Stephen Merriman: doesn't it have no differences because they are in a same length at all.. :-)
@all: easy to understand, that order just likes an order satisfying the i-th string (code) must be "less" than (i+1)-th string (code), by using operator "<" (Pascal...) or function strcmp (C...) :-)
I am getting wrong
I am getting wrong answer...can I know the test case for which it is failing
i have read previous comments
i have read previous comments but i am still doubtful... please clarify me
Limitations
plese explain with examples
plese explain with examples what is lexicological order?
as soon as possible.
@AnhDQ: please explain
@AnhDQ: please explain lexicological term with examples.
I'm not getting from given explanation.
please!
for the Limitations, please
for the Limitations, please check again the comment [ AnhDQ - 1st Aug,2010 20:55:13 ] :-)
for the "lexicological" order, again, its the way you build a normal dictionary, ok ? It's a very very normal term in informatics and life, so I think it is able for all of you to understand :-) but let us know in case you still have problems with it.
@Zakir: you are not allowed to know it :-)
@all: please read instructions in FAQ, above comments, even searching... carefully before questioning, thanks :-)
@everyone - just pretend it
@everyone - just pretend it says lexicographical. Lexicological is a mistake; it is a word, but is not related to ordering whatsoever.
@Stephen Merriman: then
@Stephen Merriman: then please explain the meaning of lexicographical with an example.
AnhDQ: that means smallest
AnhDQ: that means smallest number from the set of satisfying numbers(that produce exit code).
ok, it can be understood like
ok, it can be understood like lexicographical order, it is just not for discussing about vocabulary here, but I (we) are trying to explain the statement, then hope it ok.
@dharmendra kumar: as you read from the statement, all the codes have the same length, and it is like a "string", not only a "number" because of leading zeros (maybe), so we can compare it by method of string comparing or number comparing is ok at all :-)
There should have been at
There should have been at least one more test case ... I think
@AnhDQ sir, is your meant
@AnhDQ
sir, is your meant about lexicological is that the ith substring of the code should be less than (i+1)th substring....???
You want to make c1 as small
You want to make c1 as small as possible. Then make c2 as small as possible. And so on.
@stephen is by your if we
@stephen
is by your if we change the string to the numric value then the value should be smalll....as possible....???
because according the given test case if we change the string to numric value its value is least. than other possible cases.
@stephen i'm w8ing for you
@stephen
i'm w8ing for you response becos i used that all mehtod bt still got WA so please help.
hi=(hi-1×A+ci) mod B here
hi=(hi-1×A+ci) mod B
here equal sign refers to congruence .am i right?
@VIVEK SINGH: no, it means
@VIVEK SINGH: no, it means the operator mod (Pascal) or % (C, C++, Java...), as I replied
@AnhDQ thanks ..
@AnhDQ
thanks ..
When the number of digits in
When the number of digits in sequence is already specified ....... what does d smallest sequence means ??
ohh got it .. !!!
ohh got it .. !!!
Are any blank line after
Are any blank line after the output?
@all: the judging method is
@all: the judging method is "ignore extra whitespaces", so never mind about extra space or blank at end-of-line or file ;-)
At the end of around 20 - 25
At the end of around 20 - 25 seconds , the judge gives a WA . Does it mean that the beginning answers were right. PLease could someone check my solution
http://www.codechef.com/viewsolution/302440
No.
No.
@stephen Thanks ..
@stephen Thanks ..
@coders-who-have-submitted-in
@coders-who-have-submitted-in-python My python code is giving correct ans: 084 and the code is working reasonably fast, but it gives TLE. Are there any special pointers for this question for input/output for python which i might be overlooking? I'm using [n,A,B,G]=map(int,raw_input().split()) for input and outputting a single string: "084"
@admin My solution is showing
@admin
My solution is showing time 0.00 and MEM 1.6M. ( WA ) .
how can time be 0.00, I think there may be some error with judge.
please check , solution id-303796.
thanx
Admin...please give one more
Admin...please give one more test case....mine code is working fine on my machine but gives wrong answer while submitting.....plz help
i'm getting correct answer
i'm getting correct answer for various cases but on submission it say WA i think
i'm not getting lexcographic term clearly.
00175
00185
00266
00357
00448
00539
00720
00811
00902
from the give set is 00175 is lexicogrphically smaller? if not then which one is?
anyone please.
Yes.
Yes.
please explain the term
please explain the term lexicographical the question seems easy but don't know why getting WA.
and what would be the answer for case 12 11 111 92.?
thanx.
000000000084
000000000084
@Derengowski thanx Sir my
@Derengowski
thanx
Sir my code also producing same code could you help me to find error..u can view my code at
http://www.codechef.com/viewsolution/296706
@regards
amrit