Keep/Drop/Increase Sequence Here is the sequence I'm talking about:

{1, 4, 5, 9, 10, 11, 16, 17, 18, 19, 25, 26, 27...}


Starting from 1, keep 1, drop the next 2, keep the next 2, drop 3, keep 3 and so on. Yes, it's on OEIS (A064801), too!

The Challenge

Given an integer n&gt;0, find the nth term of the above sequence

Test Cases  

Input -&gt; Output       
1-&gt;1  
22-&gt;49  
333-&gt;683
4444-&gt;8908
12345-&gt;24747


This is code golf so the shortest answer in bytes wins! Good luck!
Java (OpenJDK 8), 45 44 bytes



n-&gt;{int i=0;for(;++i&lt;n;n-=i);return~-n+i*i;}


Try it online!

-1 byte thanks to @Nevay

After staring at this for a while, I noticed a pattern. Every time we drop n numbers, the next number in the sequence is a perfect square. Seeing this, I mentally broke the sequence into convenient chunks: [[1],[4,5],[9,10,11],...] Basically, the ith chunk starts with i*i, and iterates upwards for i elements.

To find the nth number in this sequence, we want to find first which chunk the number is in, and then which position in the chunk it occupies. We subtract our increment number i from n until n is less than i (which gives us our chunk), and then simply add n-1 to i*i to get the correct position in the chunk.

Example:

n = 8
n &gt; 1? Yes, n = n - 1 = 7
n &gt; 2? Yes, n = n - 2 = 5
n &gt; 3? Yes, n = n - 3 = 2
n &gt; 4? No, result is 4 * 4 + 2 - 1 = 17