TopCoder problem "CarrotJumping" used in Member SRM 478 (Division I Level One , Division II Level Two)



Problem Statement

    Rabbits often feel hungry, so when they go out to eat carrots, they jump as quickly as possible.



Initially, rabbit Hanako stands at position init. From position x, she can jump to either position 4*x+3 or 8*x+7 in a single jump. She can jump at most 100,000 times because she gets tired by jumping.



Carrots are planted at position x if and only if x is divisible by 1,000,000,007 (i.e. carrots are planted at position 0, position 1,000,000,007, position 2,000,000,014, and so on). Return the minimal number of jumps required to reach a carrot. If it's impossible to reach a carrot using at most 100,000 jumps, return -1.



 

Definition

    
Class:CarrotJumping
Method:theJump
Parameters:int
Returns:int
Method signature:int theJump(int init)
(be sure your method is public)
    
 

Constraints

-init will be between 1 and 1,000,000,006, inclusive.
 

Examples

0)
    
125000000
Returns: 1
She can jump from 125000000 to 1000000007.
1)
    
281250001
Returns: 2
281250001 -> 1125000007 -> 9000000063
2)
    
18426114
Returns: 58
3)
    
4530664
Returns: 478
4)
    
705616876
Returns: 100000
5)
    
852808441
Returns: -1
She can't reach any carrot by making at most 100,000 jumps.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=11022

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14187&pm=11022

Writer:

rng_58

Testers:

liympanda , konqueror , ivan_metelsky , keshav_57

Problem categories:

Math