SimpleMathProblemDiv2
TCO19 SRM 741 · 2018-10-30 · by Blue.Mary
Problem Statement
The function g(n, p) is defined for all positive integers n and all primes p. Its definition is as follows:
if n is not divisible by p:
g(n,p) = 0
otherwise:
g(n,p) = the largest power of p that does not exceed n
The function f(n) is defined for all positive integers as follows: f(n) is the sum of g(n,p) over all primes p.
You are given an
Notes
- You may assume (and also see from the Examples) that the largest possible output fits into a long.
Constraints
- X will be between 1 and 444,777, inclusive.
1 Returns: 0
2 Returns: 2
3 Returns: 5
4 Returns: 9
5 Returns: 14
8 Returns: 36
Note that f(6) = 7, because g(6,2) = 4 and g(6,3) = 3. If you think that g(6,2) should be 2, please go back and re-read the definition of g more carefully.
Submissions are judged against all 96 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SimpleMathProblemDiv2 with a public method long long calculate(int X) · 96 test cases · 2 s / 256 MB per case