-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa 11614 Etruscan Warriors Never Play Chess.cpp
80 lines (66 loc) · 1.35 KB
/
UVa 11614 Etruscan Warriors Never Play Chess.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Acccepted
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define high 1000000000000000000
typedef long long LL;
//void fun()
//{
// LL i=1 , sum=0;
//
// while(sum <= high)
// {
// sum+=i;
// i++;
// //cout << sum << "; ";
// if(sum == high)
// {
// cout << sum << " " << i;
// break;
// }
// }
//
// cout << sum << " " << i;
//}
void solution(LL t, LL m)
{
while(((t*t)+t) <= m)
{
t++;
}
cout << t-1 << "\n";
}
int main()
{
fast;
//fun();
LL n , test;
cin >> test;
while(test--)
{
// for(LL i=1; ; i++)
// {
// if(((i*i) + i ) / 2 > n)
// {
// cout << "accepted: " << i-1 << "\n" ;
// break;
// }
// }
cin >> n;
if(n == 0)
{
cout << 0 << "\n";
continue;
}
LL mul = n << 1; //cout << mul << "\n";
LL qrt = sqrt(double(mul)) - 1; //cout << "qrt = " << qrt << "\n";
if( (qrt * qrt) + qrt == mul ) cout << qrt << "\n";
else if( (qrt * qrt) + qrt > mul ) cout << qrt-1 << "\n" ;
else if( (qrt * qrt) + qrt < mul )
{
LL tmp = qrt+1;
solution(tmp, mul);
}
}
return 0;
}