`
bcyy
  • 浏览: 1818378 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多

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 integerNin the first line (1 ≤N≤ 65535). Thei-th ofNleft lines contains the integerKi— the number of position in the sequence<nobr>(1 ≤<em>K<span style="bottom:-0.4em; position:relative; vertical-align:baseline">i</span></em>≤ 2<span style="position:relative; top:-0.4em; vertical-align:baseline">31</span>− 1)</nobr>.

Output

You are to outputNdigits 0 or 1 separated with a space. More precisely, thei-th digit of output is to be equal to theKi-th digit of described above sequence.

Sample

input output
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<<' ';
	}
}




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics