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
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » September 2009 (Contest VIII) » Se7en

Se7en

Problem code: F4

  • All Submissions

All submissions for this problem are available.

Tomek and his numerous friends are standing in a circle. They are all numbered with consecutive identifiers, from 1 to 1337 in the clockwise direction. Starting from person 1, who says "1", successive people read out successive positive integers. The starting direction is clockwise, and there is rule, that whenever integer is divisible by 7 or contains digit 7, the direction is reversed.

So, the identifiers of the persons who read-out successive numbers, are: 1,2,3,4,5,6,7 (person 7 has just read "7" and reversed the direction),6,5,4,3,2,1,1337 (person 1337 has just read "14" and reversed the direction),1,2,3 (person 3 has just read "17" and reversed the direction),2,1,1337,1336, and so on. Tomek has his favorite number, and he wants to calculate where in the circle he should stand to read that number out loud. Even though he is skilled programmer, he is a bit little lazy and would like you to help him out.

Input

First, 1 ≤ t ≤ 1000, the number of test cases. Each test case is in a separate line, and contains a positive integer smaller than 10100, representing Tomek's favorite number.

Output

For each testcase, output one integer, the identifier which Tomek should choose in the circle to read his favorite integer loud.

Example

Input:
3
10
100
1000

Output:
4
2
1311

Author: admin
Date Added: 10-07-2009
Time Limit: 1 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, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

I am geting "Wrong Answer"

tarzanisgoodguy @ 2 Sep 2009 12:30 PM

I am geting "Wrong Answer" message despite the fact, that with what ever test data I am entering,  am getting the correct answer. Could the "Wrong answer" be little more specific.

Nope :)

triplem @ 2 Sep 2009 01:47 PM

Nope :)

If you are getting a WA, it

admin @ 2 Sep 2009 01:57 PM

If you are getting a WA, it means that your code gives the wrong output for one of the test cases. :)

oh man... my prog works

ash_rith @ 2 Sep 2009 07:34 PM

oh man... my prog works perfect but its gettin timed out! sigh!

 I get the correct answer for

stinger @ 2 Sep 2009 08:37 PM

 I get the correct answer for 10, 100 and 1000. i.e. 4, 2, and 1311 respectively, on my PC.

But I am getting a "WA" in CodeChef

Should the output for 3 return nothing as in the example?

Is the output format stringent? I have left a blank line after the output.

My program compiles fine on

nastrofaction @ 2 Sep 2009 11:37 PM

My program compiles fine on my compiler (JAVA) but it shows compilation error in your system.

@Akshat: Change the classname

codesnooker @ 3 Sep 2009 12:01 AM

@Akshat: Change the classname to 'Main'. The program will work then

Its already Main, still its

nastrofaction @ 3 Sep 2009 12:23 AM

Its already Main, still its not accepting... :(

Configuration of my PC

stinger @ 3 Sep 2009 01:57 AM

Configuration of my PC : 

AMD Athlon 64 X2 Dual 

Core Processor 4800+ 

2.50 Ghz, 1.75 GB RAM

 

timing results on my PC shows (after running time <program name>): 

real              0m5.500s

user             0m0.031s <Less than 1sec. as required>

sys               0m0.015s <Less than 1sec. as required>

Why does codechef show Time Limit Exceeded.

 

@Anup George The 3 in the

jdmetz @ 3 Sep 2009 02:10 AM
@Anup George The 3 in the sample input is the number of cases. When you submit, your code is judged against different inputs - not the sample inputs. Note that you could have up to 1000 cases with numbers up to 10^100, all of which must be processed within the 1s time limit.

@akshat Take a look at

admin @ 3 Sep 2009 03:09 AM

@akshat Take a look at www.codechef.com/help for more information on how to submit a problem in java.

Thamks for the help, your

nastrofaction @ 3 Sep 2009 06:25 AM

Thamks for the help, your system doesn't allow system.console, the problem got sorted. but now it says wrong ans but i have tested it for quite a cases. :(

  I was able to compile and

pda @ 3 Sep 2009 12:51 PM

 

I was able to compile and run the program successfully. But when I submit the program here, it shows me compilation error.Any idea what can I do to avoid this?

Check out the FAQ at

admin @ 3 Sep 2009 01:07 PM

Check out the FAQ at http://blog.codechef.com/2009/06/29/frequently-asked-questions/ and also the help section at www.codechef.com/help for a sample solution in your language.

I am also getting the

awmanoj @ 5 Sep 2009 01:26 PM

I am also getting the compilation error while it compiles perfect on my system. can you please mail the compilation error log?

solved. issue was "void

awmanoj @ 5 Sep 2009 02:06 PM

solved. issue was "void main()" instead of "int main()" - wrong prototype.

 i m new to code

jasra @ 5 Sep 2009 07:41 PM

 i m new to code chef.....

plzz tell me how to submit sol ie what exactly we have to submit

You have to submit a solution

admin @ 5 Sep 2009 07:57 PM

You have to submit a solution to the problem that takes input from stdin and writes output to stdout. Your program should be in one of the supported languages mentioned. It will be run against different test cases and if it produces the right answer for all of them, then it will be judged as correct, else you will get the status as Wrong answer.

 i have written a code in

jasra @ 5 Sep 2009 09:16 PM

 i have written a code in java. it is running fine on my machine but when i upload it online(code chef) it shows run time error ???

Read the FAQ and

admin @ 7 Sep 2009 02:07 PM

Read the FAQ and www.codechef.com/help

What about the no.s that

shashankp @ 14 Sep 2009 07:48 PM
What about the no.s that arent possible? llike 1,2,3... those no.s will be overwritten right...

kk.. my bad.. the no. should

shashankp @ 14 Sep 2009 07:54 PM
kk.. my bad.. the no. should only be read out..

 hi, where should i submit

him_theicy @ 16 Sep 2009 09:19 PM

 hi,

where should i submit the code........

I am not able to solve it.

bcwajapey @ 13 Apr 2011 10:32 PM

I am not able to solve it. But I am interested in knowing the algorithm. can somebody send the algorithm please ?

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 algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm 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 programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were 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 challenges 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 coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

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. You can also host a coding contest for your institute on CodeChef, organize an algorithm event 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