-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspecialSum.cpp
52 lines (45 loc) · 972 Bytes
/
specialSum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("specialSum.in");
ofstream fout("specialSum.out");
int main()
{
int count0;
fin >> count0;
for (int c = 1; c <= count0; ++c)
{
if (c != 1)
{
fout << '\n';
}
int k;
fin >> k;
if (k < 0)
{
k *= -1;
}
for (int n = sqrt(2 * k); n <= 44723; ++n)
{
if (n * (n + 1) / 2 < k)
{
continue;
}
int different = (n * (n + 1) / 2 - k);
if (different % 2 == 0 && different / 2 <= 2 * n - 1)
{
fout << n << '\n';
break;
}
}
}
return 0;
}