codeforces Mathematical Circus-div2-B
题意:
给定n,k。是否能把(1--n)的数分成符合条件的(a,b)对。
条件:(a+k)*b%4==0
解:
因为:原式=(a+k)*b≡0(mod 4)
ab+b*k≡0(mod 4)
若k>=4,bk=b*(4t+k-4t)=4t*b+b*(k-4t)
上式有:ab+b*k≡ab+b*(k-4t)+b*4t≡ab+b*(k-4t)≡0(mod 4)
也就是说,我们只需要研究k=0,1,2,3的情况
k=0时,即:ab%4==0,不妨令a is odd,b is even,式子显然不成立
k=1 or 3:一种可能是:a+k is even,b is even,这是总可以成立的
k=2:1:a is even ,b is odd then a+k is even but not always is div by 4
2: when b==4t,t>=1,is right . other b is odd,a+k is div by 4,a just is div by 2,but not div by 4.
#include<iostream> #include<cstring> #define maxn (int)(2e5+1e1) using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; while (k > 4)k %= 4; if (k == 0) { cout << "NO\n"; continue; } cout << "YES\n"; if (k == 1 || k == 3) { for (int i = 1; i <= n - 1; i += 2) { cout << i << " " << i + 1 << "\n"; } } else if (k == 2) { for (int i = 1; i <= n - 1; i += 2) { if ((i + 1) % 4 == 0)cout << i << " " << i + 1 << "\n"; else cout << i + 1 << " " << i << "\n"; } } } return 0; }
标签:Mathematical,even,ab,数论,4t,Circus,int,div From: https://www.cnblogs.com/FeiShi/p/16643293.html