P6250 题解
这题楼上奆佬已经写的很好了,但由于蒟蒻太弱,看起来有些费劲qwwq
这篇主要讲的细一些
题意
求是否存在 \sum_{i=1}^n a_i = \prod _{i=1}^n a_i = n
思路
看到样例解释中用
1. n \equiv 1(mod\ 4 ) (x \equiv y(mod\ z) 表示 x 除以 z 余 y )
设
此时就如样例情况,用
2. n \equiv 2(mod\ 4 )
这时
故
3. n \equiv 3(mod\ 4 )
引理: 若
此时
-
a_p \equiv a_q \equiv 3(mod\ 4 ) 则
a_p \times a_q \equiv 3 \times 3 \equiv 1(mod\ 4 ),a_p + a_q \equiv 3 + 3 \equiv 2(mod\ 4 ) -
a_p \equiv a_q \equiv 1(mod\ 4 ) 则
a_p \times a_q \equiv 1 \times 1 \equiv 1(mod\ 4 ),a_p + a_q \equiv 1+1 \equiv 2(mod\ 4 )
发现此时两种奇数做偶数次乘法都是模
由于
设需要
-
x \equiv 0(mod\ 4 ) 则
y \equiv n-x \equiv 3(mod\ 4 ) \Rightarrow n \equiv y \times b'+x \times b \equiv 3\times 3 + 0 \times 1\equiv 1(mod\ 4 ) ,此时n \not\equiv 3(mod\ 4 ) ,矛盾。 -
x \equiv 2(mod\ 4 ) 则
y \equiv n-x \equiv 1(mod\ 4 ) \Rightarrow n \equiv y \times b'+x \times b \equiv 1\times 3 + 2 \times 1\equiv 1(mod\ 4 ) ,此时n \not\equiv 3(mod\ 4 ) ,矛盾。
故
4. n \equiv 0(mod\ 4 )
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int k = n / 4;
switch (n % 4) {
case 1:
if (n == 1) {
cout << "YES" << endl;
cout << 1 << endl;
cout << 1 << ' ' << 1 << endl;
break;
}
cout << "YES" << endl;
cout << 3 << endl;
cout << 1 << ' ' << n << endl << 2 * k << ' ' << 1 << endl << 2 * k << ' ' << -1 << endl;
break;
case 2:
cout << "NO" << endl;
break;
case 3:
cout << "NO" << endl;
break;
case 0:
if (n == 4) {
cout << "NO" << endl;
break;
}
cout << "YES" << endl;
cout << 4 << endl;
if (k % 2) cout << 1 << ' ' << 2 * k << endl << 1 << ' ' << -2 << endl << k - 2 << ' ' << -1 << endl << 3 * k << ' ' << 1 << endl;
else cout << 1 << ' ' << 2 * k << endl << 1 << ' ' << 2 << endl << k << ' ' << -1 << endl << 3 * k - 2 << ' ' << 1 << endl;
break;
}
}
}