Problem Statement
John and Brus believe that the digits 4 and 7 are lucky and all others are not.
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 * 62 + 7, therefore representation of number 255 in the numeral system with base 62 consists of two digits, the leftmost digit is 4 and the rightmost digit is 7.
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 digits (i.e. 4 and 7). For example, base 62 is lucky for the number 255.
You are given a
Definition
- Class:
- TheLuckyBasesDivTwo
- 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^12, inclusive.
Examples
255
Returns: 1
The only lucky base for the number 255 is 62. Note that base 52 is not lucky. Representation of 255 in this base contains digits 4 and 47. The digit 47 is not lucky, even though its decimal representation contains only lucky digits. Only the digits 4 and 7 are considered to be lucky.
4
Returns: -1
All bases greater than 4 are lucky.
13
Returns: 0
No lucky bases here.
60
Returns: 2
17
Returns: 0
23
Returns: 0
52
Returns: 1
347723696
Returns: 1
925643275
Returns: 2
65038986
Returns: 0
644199585
Returns: 0
333393417
Returns: 1
255248223
Returns: 1
683104052
Returns: 1
517788483
Returns: 1
434727064
Returns: 1
610370488
Returns: 2
454765462
Returns: 1
643862778
Returns: 0
852497597
Returns: 1
619347723696
Returns: 1
257925643275
Returns: 1
120065038986
Returns: 1
914644199585
Returns: 1
912333393417
Returns: 0
215255248223
Returns: 1
191683104052
Returns: 1
164517788483
Returns: 1
493434727064
Returns: 1
728610370488
Returns: 2
919089952699
Returns: 1
957759064442
Returns: 0
919834457824
Returns: 1
914618803015
Returns: 1
912188536477
Returns: 0
1000000000000
Returns: 1
1
Returns: 0
474747477747
Returns: 3
747477474774
Returns: 1
999999999048
Returns: 1
999999999541
Returns: 1
999999999973
Returns: 0
999999999234
Returns: 0
999999999667
Returns: 2
999999999561
Returns: 0
999999999245
Returns: 0
999999999321
Returns: 0
762939453124
Returns: 2
141214768240
Returns: 3
314146179364
Returns: 2
854645986252
Returns: 1
236663697847
Returns: 2
549352360252
Returns: 2
2044801603
Returns: 2
254911373669
Returns: 1
358759972685
Returns: 1
99801488981
Returns: 1
48853923508
Returns: 2
920885238805
Returns: 2
5695231426
Returns: 1
156915327850
Returns: 1
248176054407
Returns: 2
60471954180
Returns: 2
479064391809
Returns: 1
124999994016
Returns: 2
278013940
Returns: 2
253706887
Returns: 3
392716078000
Returns: 2
468305010
Returns: 1
123079338204
Returns: 3
35016046314
Returns: 2
34312041063
Returns: 2
2782467538
Returns: 2
26689021741
Returns: 2
999998000004
Returns: 2
9999887898
Returns: 1
999999999999
Returns: 2
44444444451
Returns: 1
4000000004
Returns: 2
99999999999
Returns: 2
100000000000
Returns: 1
99798999447
Returns: 2
1000000000
Returns: 1
2760721
Returns: 1
47
Returns: 1
4747
Returns: 2
44
Returns: 1
9999999019
Returns: 1
156464699494
Returns: 0
8
Returns: 0
63
Returns: 2
1684
Returns: 4
532
Returns: 3
744
Returns: 2
100000000007
Returns: 1
17048794
Returns: 2
12345678901
Returns: 0
14
Returns: 0
77
Returns: 1
4000008
Returns: 1