Hyeongwon and the Curious Sequence
InterviewTime limit0.1sMemory limit1024 MB
Given N, compute A_N, where A_0 is 0 and each step subtracts i from the previous value unless the result is negative or already used, in which case it adds i.
- Level
Easy3 of 10
- Topics
- Simulation, Hash map
- Solved
- No attempts yet
Problem
Hyeongwon likes looking for curious sequences. While searching as usual, he found an interesting sequence .
Sequence satisfies the following conditions.
-
- However, if the computed by the rule above is negative or already appears among , then .
Hyeongwon wants a program that computes the sequence. Help him write a program that, given , finds .
Input
The first line contains a non-negative integer .
Output
Print on the first line.