Undiv2
SRM 691 · 2016-05-02 · by subscriber
SRM 691 · 2016-05-02 · by subscriber · Math
Problem Statement
Problem Statement
Given a positive integer x, let s(x) be the second smallest positive integer that does not divide x.
int n.
Compute and return the sum of the n numbers on Hero's paper.
For example, let x = 6. The integers that do not divide x are 4, 5, 7, 8, 9, 10, ... The second smallest of these is 5. Hence we have s(6) = 5.
Hero took a blank sheet of paper. For each i between 1 and n, inclusive, he computed the value s(i) and wrote it on the paper. You are given theConstraints
- n will be between 1 and 1,000,000,000, inclusive.
Examples
0)
1 Returns: 3
The smallest two positive integers that don't divide 1 are 2 and 3. Thus, we have s(1) = 3.
1)
2 Returns: 7
2)
3 Returns: 11
The answer is s(1) + s(2) + s(3) = 3 + 4 + 4 = 11.
3)
5 Returns: 19
4)
8 Returns: 32
Submissions are judged against all 73 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Undiv2 with a public method long long getsum(int n) · 73 test cases · 2 s / 256 MB per case