Seq
Accepts: 1249 Submissions: 3956
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
Input
Output
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;
}