-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathCHFNSWAP.cpp
52 lines (47 loc) · 1005 Bytes
/
CHFNSWAP.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
code chef sept long challenge div 2
/*https://www.codechef.com/SEPT20B/status/CHFNSWAP*/
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll function1(ll sm)
{
long double a=sqrtl(1ul + 4*(sm));
a=a-1.0;
a=a/2.0;
ll fs=a;
return fs;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n==0 || n==1 || n==2)
{ cout<<0<<"\n";
continue;}
ll total=n*(n+1)/2;
if(total%2!=0)
{
cout<<"0"<<"\n";
continue;
}
ll index=function1(total);
ll ss=index*(index+1)/2;
if(total/2==ss)
{
ll out=index*(index-1ul)/2l+((n-index)*(n-index-1ul))/2l+(n-index);
cout<<out<<endl;
}
else
{
cout<<n-index<<endl;
}
}
}