The Ulam Sequence
HardAcc. 73.1%
+45 XP 25
Unique Additions
The Ulam Sequence ($U_n$) starts with $U_1=1, U_2=2$. Every subsequent number is the smallest integer that can be represented as the sum of exactly two distinct earlier terms in exactly one way. 1, 2, 3 (1+2), 4 (1+3), 6 (2+4)... (5 is skipped because it's 1+4 AND 2+3).
The Assignment
Your function receives a parameter count.
- Maintain a list (array) of sequence members.
- Search for the next smallest number that fits the "single way sum" rule using nested loops over the current members.
- Print exactly
countnumbers.
01EXAMPLE 1
Input
count=5Output
1
2
3
4
6Explanation: 5 is excluded (two ways to sum).
Constraints
- Use nested loops for the sum check.
- Print each result on a new line.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
count5
Expected Output
1 2 3 4 6
Click RUN to test your solution