Register Now
Member Count: 491,060 - June 19, 2013  [Get Time]
Login

   Problem Statement  

 Problem Statement for TheLuckyBasesDivOne

Problem Statement

    

John and Brus believe that the digits 4 and 7 are lucky and all others are not. According to them, a lucky number is a number that contains only lucky digits in its decimal representation.

Recently, they became interested in numeral systems with different bases. Normally, people use the numeral system with base 10 to represent numbers, however, there exist numeral systems with other bases. More exactly, for each integer B, B >= 2, there exists a numeral system with base B. In this system, there are B different digits, used to represent numbers from 0 to B-1, inclusive. In order to represent a positive integer A in such system, it's necessary to find such digits a[n], a[n-1], ..., a[0], that A = a[n] * B^n + a[n-1] * B^(n-1) + ... + a[0] * B^0 (here ^ denotes the power operator), and then write these digits from left to right, in this exact order. For example, 255 = 4 * 52 + 47, therefore representation of number 255 in the numeral system with base 52 consists of two digits, the leftmost digit is 4 and the rightmost digit is 47.

The base of numeral system B is called lucky for some integer number A if all digits of the number A represented in numeral system with base B are the lucky numbers (i.e. 4, 7, 44, 47, ...). For example, base 52 is lucky for the number 255.

You are given a long n. Return the total number of lucky bases for the number n. If there are infinitely many such lucky bases, return -1 instead.

 

Definition

    
Class:TheLuckyBasesDivOne
Method:find
Parameters:long
Returns:long
Method signature:long find(long n)
(be sure your method is public)
    
 

Constraints

-n will be between 1 and 10^16, inclusive.
 

Examples

0)
    
255
Returns: 2
There are two lucky bases for the number 255: 52 and 62.
1)
    
474
Returns: -1
All bases greater than 474 are lucky.
2)
    
13
Returns: 0
No lucky bases here.
3)
    
4748
Returns: 5

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 510 Round 1 - Division I, Level Three