Seq[找规律]----2019 年百度之星·程序设计大赛 - 初赛一:1005

Seq

Accepts: 1249   Submissions: 3956
Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 32768/32768 K (Java/Others)

Problem Description

"度度熊有一个递推式 ,现给出 n,需要求 an​​ 。"

Input

"第一行输入一个整数 T,代表T (1≤T≤100000) 组数据。 接下 T 行,每行一个数字 n (1≤n≤10^{12}​​ )。"

Output

"输出 T 行,每行一个整数表示答案。"

Sample Input

5
1
2
3
4
5

Sample Output

1
1
0
3
0

此题做题时看数据范围较大,便猜想是否有规律,随即递推打印出了前1000项的结果:

发现似乎真有规律,便写出如下代码,提交通过。

代码如下:

//1005
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	
	long long  t,n;
	cin >> t;
	while(t--){
		cin >> n;
		if(n%6 == 0)cout << n / 2<<endl;
		if(n%6 == 1)cout << 1 + 4 * (n/6)<<endl;
		if(n%6 == 2)cout << 1 + 3 * (n/6)<<endl;
		if(n%6 == 3)cout << n / 6 <<endl;
		if(n%6 == 4)cout << n - 1 <<endl;
		if(n%6 == 5)cout << n / 6 <<endl;
	}
	
	return 0;
}
posted @ 2019-08-17 21:51  我不是张小毛  阅读(241)  评论(0编辑  收藏  举报