POJ 1430

上面的估计是题解吧。。。。呃,如果真要用到公式的话,确实没听过。。。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#define LL __int64

LL work(LL n){
	LL res=0; LL divd=2;
	while(divd<=n){
		res+=(n/divd);
		divd=(divd<<1);
	//	cout<<divd<<endl;
	}
	return res; 
}

int main(){
	LL n,k;
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%I64d%I64d",&n,&k);
		LL z=n-(LL)((k+2)/2);
		LL w=(k-1)/2;
		if(work(z)-work(w)-work(z-w)==0)
		printf("1\n");
		else printf("0\n");
	}
	return 0;
}

  

posted @ 2014-10-12 11:32  chenjunjie1994  阅读(227)  评论(0编辑  收藏  举报