The Task
Given an input positive integer n
(from 1 to your language's limit, inclusively), return or output the maximum number of distinct positive integers that sum to n
.
Test Cases
Let f
define a valid function according to the task:
The sequence for f
, starting at 1:
1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, ...
As a larger test case:
>>> f(1000000000) // Might not be feasible with brute-forcers
44720
Test Code
For any test cases not explicitly given, the output of your code should match the result of the following:
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println((int) Math.floor(Math.sqrt(2*x + 1./4) - 1./2));
}
}