-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTRICOIN.c
45 lines (39 loc) · 802 Bytes
/
TRICOIN.c
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
#include<stdio.h>
#define N_MAX 100000
long long int sum[N_MAX];
void precompute(){
int i;
sum[0]=0;
for(i=1;i<N_MAX;i++){
sum[i]=sum[i-1]+i;
}
}
long long int search(long long int n){
int start=0,end=N_MAX-1;
int mid;
while(1){
mid = (start+end)/2;
if(sum[mid] == n){
return mid;
}else if(sum[mid]< n && sum[mid+1]>n){
return mid;
}else if(sum[mid]>n){
end=mid;
} else if(sum[mid]<n){
start=mid;
}
}
return -1;
}
int main(){
precompute();
int tc,T;
scanf("%d",&T);
for(tc=0;tc<T;tc++){
long long int n,i, height;
scanf("%lld", &n);
height = search(n);
printf("%lld\n",height);
}
return 0;
}