Problem Statement
NOTE: This problem statement contains superscripts that may not display properly if viewed outside of the applet.
In John's country, the main religion is based on holy numbers. The religion claims something silly like "the holy numbers are those that contain only 4s and 7s in their decimal expansion".
John is a heretic. He does believe in holy numbers, but he is convinced that the religion is mistaken in their definition. The holiness of a number simply cannot depend on the base in which it is represented! After a long meditation, John realized that the prime factorization of a number does not depend on the base in which the number is represented. That was the correct way!
Many years later, John's theory was finally ready. A prime p likes the number x if one of the following two conditions is satisfied:
- The prime p does not divide x.
- The prime p does divide x, p is less than or equal to maximalPrime, and the highest power of p that divides x is odd. (In other words, there is a positive odd integer k such that pk divides x, and pk+1 does not divide x.)
The number x is considered holy if all primes like it.
You are given a
Definition
- Class:
- HolyNumbers
- Method:
- count
- Parameters:
- long, int
- Returns:
- long
- Method signature:
- long count(long upTo, int maximalPrime)
- (be sure your method is public)
Notes
- A prime number is a positive integer with exactly 2 positive integer divisors. The first few primes are 2, 3, 5, 7, 11, ...
Constraints
- upTo is between 1 and 1010, inclusive.
- maximalPrime is between 1 and 106, inclusive.
Examples
10
100
Returns: 8
1, 2, 3, 5, 6, 7, 8 and 10 are holy numbers.
10
3
Returns: 5
5, 7 and 10 are no longer holy.
10000000000
1000000
Returns: 3336332555
1
1
Returns: 1
2
2
Returns: 2
123
12
Returns: 32
10000000000
100
Returns: 1746758
123
456
Returns: 88
123456789
12345
Returns: 25994500
10000000000
1
Returns: 1
1
1000000
Returns: 1
5241113320
512431
Returns: 1668827996
6746828174
968291
Returns: 2320613033
8399637274
641448
Returns: 2653336377
5221324628
383675
Returns: 1581239056
4864723792
743649
Returns: 1656019874
740878
6077
Returns: 279946
572774
9198
Returns: 242951
251889
7160
Returns: 113632
367905
5948
Returns: 152097
759462
1352
Returns: 184730
359790
3787
Returns: 135545
679180
2392
Returns: 205763
90807
3981
Returns: 42037
901147
4135
Returns: 303109
793177
6954
Returns: 305646
4063067882
3632
Returns: 229286987
146
171
Returns: 106
2
52775
Returns: 2
574415810
11
Returns: 1700
560011
625552
Returns: 394518
1799455
9
Returns: 315
14639
577
Returns: 5816
787
3
Returns: 16
5014
11842
Returns: 3540
50
2557
Returns: 36
24252681
3279
Returns: 4098988
4226
3
Returns: 22
149
54228
Returns: 107
2835404662
133504
Returns: 742041902
5836
3
Returns: 23
55675284
151831
Returns: 22686774
25465
469
Returns: 8541
1481959
2611
Returns: 401004
423246
30471
Returns: 224669
1307008
3
Returns: 49
2120876497
11
Returns: 2093
1531259442
365
Returns: 11331396
6477
148
Returns: 1857
974872
6
Returns: 131
1146835
11
Returns: 525
2524812301
18
Returns: 7631
7
1398
Returns: 6
17657696
93
Returns: 107200
2708044
789
Returns: 368224
979
24183
Returns: 691
464
2
Returns: 5
1169
9
Returns: 57
62020404
411
Returns: 1863966
34
5272
Returns: 26
100204676
68
Returns: 118104
78491
626239
Returns: 55305
7036
3599
Returns: 4556
10
3885
Returns: 8
216
45
Returns: 101
2275879360
2239
Returns: 104818111
478379
172269
Returns: 307353
3
327
Returns: 3
2427747145
1137
Returns: 61545737
147
130230
Returns: 106
1238
35
Returns: 256
57461072
2
Returns: 14
163
36
Returns: 74
15
589
Returns: 12
228673
87384
Returns: 146932
2611634
28228
Returns: 1125276