#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <random>
#include <cfloat>
#include <chrono>
#include <bitset>
#include <complex>
#include <immintrin.h>
#include <cassert>
int64_t int_sqrt(int64_t n) {
int64_t res = 0;
for(int64_t i = 1; i * i < n; i++)
res = i;
return res + 1;
}
int main() {
int64_t n;
std::cin >> n;
int64_t block = (int_sqrt(1 + 8 * n)) / 2;
int64_t block_end = block * (block + 1) / 2;
int64_t block_start = block_end - block + 1;
std::cout << block_start + (block - 1) * (block - 2) / 2 + (n - block_start) * 2;
return 0;
}
//0 0 1 3 6 10
//1, 2, 4, 5, 7, 9, 10, 12, 14, 16, 17 19 21 23 25 26
//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
272 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
204 KB |
Output is correct |
9 |
Correct |
24 ms |
288 KB |
Output is correct |
10 |
Correct |
61 ms |
272 KB |
Output is correct |
11 |
Correct |
289 ms |
276 KB |
Output is correct |
12 |
Correct |
614 ms |
272 KB |
Output is correct |
13 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |