我是达标找规律AC的,谁能帮我证明吗
查看原帖
我是达标找规律AC的,谁能帮我证明吗
723466
banned_gutongxing楼主2025/1/25 07:59

我找到的规律是:

对于第 kk 个数,他一定是第它二进制下每一个 11 所代表的数个数的异或和。

帮我证明一下可以吗?

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
namespace gtx{
//	Fast IO
	void read(int &x){
		x = 0;int h = 1;char tmp;
		do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp));
		while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar();
		x*=h;
	}
	void read(char &x){do{x=getchar();}while(x==' '||x=='\n'||x=='\r');}
	void write(char x){putchar(x);}
	void write(int x){
		if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0;
		do st[++tot]=x%10,x/=10; while(x);
		while(tot){putchar(st[tot--]+'0');}
	}
	void write(int x,char y){write(x);write(y);}
#ifndef int
	void read(long long &x){
		x = 0;int h = 1;char tmp;
		do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp));
		while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar();
		x*=h;
	}
	void write(long long x){
		if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0;
		do st[++tot]=x%10,x/=10; while(x);
		while(tot){putchar(st[tot--]+'0');}
	}
	void write(long long x,char y){write(x);write(y);}
#endif
	int y[60] = {1,10,34,68,130,514,1028,2050,4112,8194,16388
,32770,131074,262148,524290,1048592,2097154, 4194308
,8388610,16777472,33554434,67108868,134217730,268435472,536870914
,1073741828,2147483650,8589934594,17179869188,34359738370
};
	signed main(){
		int k;
		cin >> k;
		int u = 0;
		int ans = 0;
		while(k){
			if(k&1){
				ans^=y[u];
			}
			u++;
			k>>=1;
		}
		write(ans);
		return 0;
	}
}
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
//	gtx::read(T);
	while(T--) gtx::main();
	return 0;
}
2025/1/25 07:59
加载中...