SparseFactorialDiv2
SRM 596 · 2013-06-25 · by ir5
Problem Statement
Constraints
- lo will be between 1 and 1,000,000,000,000, inclusive.
- hi will be between lo and 1,000,000,000,000, inclusive.
- divisor will be between 2 and 997, inclusive.
- divisor will be a prime number.
Statement by TopCoder, Inc. — view the original on the archive.
4 8 3 Returns: 3
The value of F(n) for each n = 4, 5, ..., 8 is as follows. F(4) = 4*3 = 12 F(5) = 5*4*1 = 20 F(6) = 6*5*2 = 60 F(7) = 7*6*3 = 126 F(8) = 8*7*4 = 224 Thus, F(4), F(6), F(7) are divisible by 3 but F(5) and F(8) are not.
9 11 7 Returns: 1
F(9) = 9*8*5 = 360 F(10) = 10*9*6*1 = 540 F(11) = 11*10*7*2 = 1540 Only F(11) is divisible by 7.
1 1000000000000 2 Returns: 999999999999
Watch out for the overflow.
16 26 11 Returns: 4
10000 20000 997 Returns: 1211
Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SparseFactorialDiv2 with a public method long long getCount(long long lo, long long hi, long long divisor) · 77 test cases · 2 s / 256 MB per case