-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjuly_loc1_method2.cpp
More file actions
48 lines (48 loc) · 918 Bytes
/
july_loc1_method2.cpp
File metadata and controls
48 lines (48 loc) · 918 Bytes
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
#include<iostream>
#include<math.h>
#define ll long long int
using namespace std;
ll func(ll n)
{
return (n*(n+1))/2;
}
ll search(ll low,ll high,ll c)
{
ll i;
for(i=low;i<=high;i++)
if(func(i)>=c)
return i;
}
int main()
{
ll no,n,low,high,c;
cin>>no;
while(no--)
{
cin>>n>>c;
if(func(n)<c)
cout<<"-1"<<endl;
else
{
low=1,high=2;
while(1)
{
if(func(low)<c&&func(high)<c)
{
low=high;
high=high*2;
}
else if(func(low)>c&&func(high)>c)
{
cout<<"-1"<<endl;
break;
}
else if(func(low)<=c&&func(high)>=c)
{
cout<<search(low,high,c);break;
}
}
}
}
return 0;
}