思路:
参考了大佬的题解orz;
感兴趣可以去看看哇qwq
首先我们可以推出,当n为奇数的时候是不可以轻易搜索出古娜拉黑暗之神的,也就是无解的情况;
- n为奇数,奇数的因子也都为奇数;
- 奇数个奇数相加为奇数,而0是偶数,与题意冲突;
我们已经排除了奇数的情况,然后我们可以手写一下偶数的各种情况,可以发现只有n被4整除的时候才可以分解
(具体证明大家看大佬的分析,上面有链接)
- 4 = 2 * (-2) * 1 * (-1)
- 8 = (-2) * (-4) * 16 * (-1)0
- 12 = 2 * (-6) * 17 * (-1)3
- 16 = (-2) * (-8) * 112 * (-1)2
- 20 = 2 * (-10) * 113 * (-1)5
- 24 = (-2) * (-12) * 118 * (-1)4
- 28 = 2 * (-14) * 119 * (-1)7
- ······
因为比较笨,所以我多写了一些样例;
x = n / 4;
我们可以发现:
- 当x为奇数时,分解式的前两项为2 * (-2 * x),1的个数为3 * x - 2,(-1)的个数为 x
- 当x为偶数时,分解式的前两项为(-2) * (-2 * x),1的个数为3 * x,(-1)的个数为 x - 2
到此就结束了,参考了大佬的题解恍然大悟,感谢感谢orz
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <stack>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#define Ilove return
#define pjq 0
#define mes memset
#define mec memcpy
using namespace std;
typedef long long ll;
typedef pair<int, int>PII;
const int N = 100010;
const int null = 0x3f3f3f3f;
const ll mod = 1000000007;
int n, T;
int main()
{
cin >> T;
while (T --)
{
cin >> n;
if (n % 4 != 0)
{
puts("w33zAKIOI");
continue;
}
int x = n / 4;
if (x & 1)
{
cout << "2 " << -2 * x << " ";
for (int i = 0; i < 3 * x - 2; i++)
{
cout << "1 ";
}
for (int i = 0; i < x; i++)
{
cout << "-1 ";
}
puts("");
}
else
{
cout << "-2 " << -2 * x << " ";
for (int i = 0; i < 3 * x; i++)
{
cout << "1 ";
}
for (int i = 0; i < x - 2; i++)
{
cout << "-1 ";
}
puts("");
}
}
Ilove pjq;
}