题解:P12388 Easy Equation
思路
我们考虑化柿子,首先我们可以设
代码
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
//#define int long long
#define fire signed
#define il inline
template<class T> il void print(T x) {
if(x<0) printf("-"),x=-x;
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
template<class T> il void in(T &x) {
x = 0; char ch = getchar();
while (ch < '0' || ch > '9') {ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
}
int T=1;
int n;
const int N=1e7+10;
int a[N],f[N];
int cc[N*2];
vector<int>v[30];
int vis[30][30];
void solve() {
in(n);
rep(i,1,n*2) cc[i]=cc[i/2]+(i&1);
rep(a,1,22) {
rep(b,a,22) {
if(__gcd(a,b)==1) {
if(a==b) v[a].pb(b);
else v[b].pb(a);
}
}
}
rep(a,1,22) {
for(auto b:v[a]) {
int tt=0;
rep(k,1,n/max(a,b)) {
if(cc[(a+b)*k]==max(a,b)) {
if(a!=b) f[max(a*k,b*k)]+=2;
else f[a*k]++;
}
}
}
}
int res=0;
rep(i,1,n) f[i]+=f[i-1],res^=f[i];
print(res);
}
fire main() {
while(T--) {
solve();
}
return false;
}
要卡下常。