您的位置:首页 > 其它

Timus 1209. 1, 10, 100, 1000... 根据数列推导公式

2014-04-24 10:35 483 查看
Let's consider an infinite sequence of digits constructed of ascending powers of 10 written one after another. Here is the beginning of the sequence: 110100100010000… You are to find out what digit
is located at the definite position of the sequence.


Input

There is the only integer N in the first line (1 ≤ N ≤ 65535). The i-th of N left lines contains the integer Ki —
the number of position in the sequence (1 ≤ Ki ≤ 231 − 1).


Output

You are to output N digits 0 or 1 separated with a space. More precisely, the i-th digit of output is to be equal to the Ki-th
digit of described above sequence.


Sample

inputoutput
4
3
14
7
6

0 0 1 0

这道题的关键就是要推导出公式了,如果使用循环,那么肯定是超时的。

根据数列的特征,知道循环的周期是1, 2, 3, 4, 5……

那么就可以知道需要计算k的位置是到了那个周期了,提示到这,看程序吧

void sequence1101001000()
{
	int T = 0;
	long long k = 0, n = 0;
	cin>>T;
	while (T--)
	{
		cin>>k;
		if (k < 3) 
		{
			cout<<1<<' ';
			continue;
		}
		n = sqrt((double)(k<<1));
		n = ((1+n)*n)>>1;
		if (n+1 == k) cout<<1<<' ';
		else cout<<0<<' ';
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: