HDU 7105 Power Sum

题面

题解

构造

注意到平方差 \((x+1)^2-x^2=2x+1\)

两个平方差的差为 \((x+3)^2-(x+2)^2-(x+1)^2+x^2=4\)

这意味着任意位置的串 1001 带来值 \(4\)

于是只需构造 \(N\mod 4\) 的余数。

代码

//https://acm.dingbacode.com/showproblem.php?pid=7105
//20211014 nksbwen

#include <iostream>
#include <string>

using namespace std;

int T;
int N;

string Base[4]={"", "1", "0001", "01"};

int main(){
	
	scanf("%d", &T);
	
	while(T--){
		scanf("%d", &N);
		
		string Ans=Base[N&3];
		N-=N&3;
		while(N){
			Ans+="1001";
			N-=4;
		}
		
		printf("%llu\n", Ans.length());
		cout << Ans << endl;
	}
	
	
	return 0;
}
posted @ 2021-10-14 11:46  Pickupwin  阅读(19)  评论(0编辑  收藏  举报