Problem Description
度度熊有一个递推式
其中 a1=1。现给出 n,需要求 an。Input
第一行输入一个整数 T,代表 T (1≤T≤100000) 组数据。
接下 T 行,每行一个数字 n (1≤n≤1012)。Output
输出 T 行,每行一个整数表示答案。
Sample Input
5
1
2
3
4
5Sample Output
1
1
0
3
0
思路:打个表找规律即可
void get(){
a[1]=1;
for(int i=2;i<=100;i++){
int sum=0;
for(int j=1;j<i;j++)
sum+=(j*a[j]);
a[i]=sum%i;
}
}
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
const int MOD = 1E9+7;
const int N = 6000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int main() {
int t;
scanf("%d",&t);
while(t--) {
LL n;
scanf("%lld",&n);
LL res=0;
if(n%2) {
if((n-1)%6==0)
res=(n-1)/6*4+1;
else {
if((n-3)%6==0)
res=(n-3)/6;
else
res=(n-5)/6;
}
}
else {
if(n<4)
res=n/2;
else if((n-4)%6==0)
res=n-1;
else
res=n/2;
}
printf("%lld\n",res);
}
return 0;
}