题目如下:
题解 or 思路:
我们可以发现:除了
n
=
=
2
n == 2
n==2 无解, 其他情况答案至少为
n
+
1
2
\frac{n+ 1}{2}
2n+1
答案在
n
+
1
2
\frac{n + 1}{2}
2n+1 到
n
n
n 之间
我们可以假设 答案为
a
n
s
ans
ans
最优摆放为:
所以可以二分去求解
求最大
a
n
s
ans
ans 满足 :
a
n
s
∗
3
−
n
+
1
2
∗
2
≤
n
ans * 3 - \frac{n + 1}{2} * 2 \le n
ans∗3−2n+1∗2≤n
AC 代码如下:
/*
Make it simple and keep self stupid
author:Joanh_Lan
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <bitset>
#include <set>
#include <random>
#include <ctime>
#include <queue>
#include <stack>
#include <climits>
#define buff \
ios::sync_with_stdio(false); \
cin.tie(0);
// #define int long long
#define ll long long
#define PII pair<int, int>
#define px first
#define py second
typedef std::mt19937 Random_mt19937;
Random_mt19937 rnd(time(0));
using namespace std;
const int mod = 1e9 + 7;
const int inf = 2147483647;
const int N = 100009;
// int Mod(int a,int mod){return (a%mod+mod)%mod;}
// int lowbit(int x){return x&-x;}//最低位1及其后面的0构成的数值
// int qmi(int a, int k, int p){int res = 1 % p;while (k){if (k & 1) res = Mod(res * a , p);a = Mod(a * a , p);k >>= 1;}return res;}
// int inv(int a,int mod){return qmi(a,mod-2,mod);}
// int lcm(int a,int b){return a*b/__gcd(a,b);}
void solve()
{
ll n;
cin >> n;
if (n == 2)
{
cout << "-1\n";
return;
}
ll l = (n + 1) / 2, r = n;
while (l < r)
{
ll mid = l + r + 1ll >> 1;
if (mid * 3 - (n + 1) / 2 * 2<= n)
l = mid;
else
r = mid - 1;
}
cout << l << '\n';
}
int main()
{
buff;
int _;
cin >> _;
while (_--)
solve();
}