CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » August 2010 Challenge » Exit code

Exit code

Problem code: ECODE

  • All Submissions

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 92
    
    Output:
    084
    

    Limitations

    * 1<=n<=12
    * 10<=A,B<=1015
    * 0<=G<B
    * The input satisfies that the answer always exist.



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


  • Submit

Comments

  • Login or Register to post a comment.

hi=h(i-1)A+... Does this

vijay_kansal @ 1 Aug 2010 04:58 PM

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

anhdq_adm @ 1 Aug 2010 06:55 PM

@Vijay Kansal: yes, "x" means producting!

should i specify inside the

vinjith @ 1 Aug 2010 07:22 PM
should i specify inside the code that * 1<=n<=12 * 10<=A,B<=1015 * 0<=G

You may take it for granted

keghani @ 1 Aug 2010 08:12 PM

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

keghani @ 1 Aug 2010 08:13 PM

@Admin: there is a typo in the Limitations section on the upper limit of A and B.

What is the time limit?

keghani @ 1 Aug 2010 08:37 PM

What is the time limit?

@all: there is some errors

anhdq_adm @ 1 Aug 2010 08:55 PM

@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

mmaxio @ 1 Aug 2010 10:17 PM

In limitations, 10<=A,B<=1015 should be 10<=A,B<=1015 .

I think I'm a little confused

keghani @ 1 Aug 2010 11:00 PM

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 ?

forest @ 2 Aug 2010 12:15 AM

what's the time limit ?

is there exist more than 1

dabbcomputers @ 2 Aug 2010 02:00 AM

is there exist more than 1 possible answer if yes then which should we have to priint.....??

are A and B of the form

chetan1507 @ 2 Aug 2010 02:11 AM

are A and B of the form 10^i??

sorry !! got it

chetan1507 @ 2 Aug 2010 02:15 AM

sorry !! got it

@Amritipal - by definition of

triplem @ 2 Aug 2010 05:32 AM

@Amritipal - by definition of 'smallest' the answer must be unique.

what is lexicological order??

vijay_kansal @ 2 Aug 2010 12:07 PM

what is lexicological order??

@vijay hit google.......

dabbcomputers @ 2 Aug 2010 02:09 PM

@vijay

hit google.......

is there a blank line after

dabbcomputers @ 2 Aug 2010 06:13 PM

is there a blank line after the output.....??? plz rply....

Could you please answer the

pdwd @ 2 Aug 2010 06:39 PM

Could you please answer the question about time limit?

@Keghani Kouzoujian: mod

anhdq_adm @ 2 Aug 2010 06:45 PM

@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

v_new.c @ 2 Aug 2010 06:59 PM

is all hi for 12 digit can hold inside int

if  a and B are very large.

@AMRITPAL SINGH: yes @atul:

anhdq_adm @ 2 Aug 2010 09:37 PM

@AMRITPAL SINGH: yes

@atul: no comment ;-)

What if A and B have numbers

Sanji @ 3 Aug 2010 02:02 PM

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

triplem @ 3 Aug 2010 03:35 PM

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

anhdq_adm @ 3 Aug 2010 05:26 PM

@Kaushik N. Sanji: anything not a "code" must be used like a "number"

can you give some more test

hector_rj @ 3 Aug 2010 06:17 PM

can you give some more test cases.

@Stephen Merriman Sorry for

Sanji @ 3 Aug 2010 07:50 PM

@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

dabbcomputers @ 3 Aug 2010 08:30 PM

is lexological means that number should smallest while moving from left to right.... Am i right....???

what is the time limit?

kiran2013 @ 3 Aug 2010 11:31 PM

what is the time limit?

This is lexicographical

pdwd @ 3 Aug 2010 11:44 PM

This is lexicographical order, I also wonder what is lexicological order?

@all: Time Limit is 6s as I

anhdq_adm @ 4 Aug 2010 03:34 AM

@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

triplem @ 4 Aug 2010 06:49 AM

@AnhDQ: As mentioned in the comment above yours, I think you meant lexicographical order, not lexicological order.

someone please explain the

gomsi_ @ 4 Aug 2010 04:22 PM

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

anhdq_adm @ 4 Aug 2010 05:44 PM

@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

skzakir7132002 @ 4 Aug 2010 09:47 PM

I am getting wrong answer...can I know the test case for which it is failing

i have read previous comments

anshulgoyal @ 4 Aug 2010 11:49 PM

i have read previous comments but i am still doubtful... please clarify me

Limitations

* 10<=A,B<=1015 (One thousand fifteen)
Is it "one thousand fifteen" or (10^15).. !

plese explain with examples

dk1990 @ 5 Aug 2010 01:03 AM

plese explain with examples what is lexicological order?

as soon as possible.

@AnhDQ: please explain

v_new.c @ 5 Aug 2010 02:25 AM

@AnhDQ: please explain lexicological term with examples.

I'm not getting from given explanation.

please!

 

for the Limitations, please

anhdq_adm @ 5 Aug 2010 04:05 AM

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

triplem @ 5 Aug 2010 06:50 AM

@everyone - just pretend it says lexicographical. Lexicological is a mistake; it is a word, but is not related to ordering whatsoever.

@Stephen Merriman: then

gomsi_ @ 5 Aug 2010 08:15 AM

@Stephen Merriman: then please explain the meaning of lexicographical with an example.

AnhDQ: that means smallest

dk1990 @ 5 Aug 2010 10:06 AM

AnhDQ: that means smallest number from the set of satisfying numbers(that produce exit code).


ok, it can be understood like

anhdq_adm @ 5 Aug 2010 10:26 AM

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

gopi6sigma @ 5 Aug 2010 01:29 PM

There should have been at least one more test case ... I think

@AnhDQ sir, is your meant

dabbcomputers @ 5 Aug 2010 04:38 PM

@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

triplem @ 5 Aug 2010 04:40 PM

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

dabbcomputers @ 5 Aug 2010 05:19 PM

@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

dabbcomputers @ 5 Aug 2010 10:03 PM

@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

vfix @ 6 Aug 2010 02:33 AM

hi=(hi-1×A+ci) mod B

here equal sign refers to congruence .am i right?

@VIVEK SINGH: no, it means

anhdq_adm @ 6 Aug 2010 04:53 AM

@VIVEK SINGH: no, it means the operator mod (Pascal) or % (C, C++, Java...), as I replied

@AnhDQ thanks ..

vfix @ 6 Aug 2010 08:51 AM

@AnhDQ

thanks ..

When the number of digits in

AnoopNarang @ 6 Aug 2010 06:52 PM

When the number of digits in sequence is already specified ....... what does d smallest sequence means ??

ohh got it .. !!!

AnoopNarang @ 6 Aug 2010 07:45 PM

ohh got it .. !!!

  Are any blank line after

Najmuzzaman @ 6 Aug 2010 11:02 PM

 

Are any blank line after the output?

@all: the judging method is

anhdq_adm @ 7 Aug 2010 06:06 AM

@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

nutsnbolts @ 8 Aug 2010 10:07 AM

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.

triplem @ 8 Aug 2010 11:17 AM

No.

@stephen Thanks ..

nutsnbolts @ 8 Aug 2010 11:19 AM

@stephen Thanks ..

@coders-who-have-submitted-in

sagarjauhari @ 8 Aug 2010 09:05 PM

@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

anshulgoyal @ 9 Aug 2010 06:30 PM

@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

code.freak @ 10 Aug 2010 12:13 PM

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

v_new.c @ 10 Aug 2010 10:52 PM

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.

triplem @ 11 Aug 2010 02:32 AM

Yes.

please explain the term

dabbcomputers @ 11 Aug 2010 07:17 PM

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

pdwd @ 11 Aug 2010 09:47 PM

000000000084

@Derengowski thanx Sir my

dabbcomputers @ 15 Aug 2010 05:57 PM

@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

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com