2019百度之星程序设计大赛 1005 Seq

Problem Description
度度熊有一个递推式 a_{n} = (\sum_{i=1}^{n-1} a_{i}*i) % na
​n
​​ =(∑
​i=1
​n−1
​​ a
​i
​​ ∗i)%n 其中 a_1 = 1a
​1
​​ =1。现给出 nn,需要求 a_na
​n
​​ 。

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

Output
输出 TT 行,每行一个整数表示答案。

Sample Input
5
1
2
3
4
5
Sample Output
Copy
1
1
0
3
0

Solution

  • 数据很大,所以刚开始以为是一道的数学题,递推式总觉得像在哪见过就一直想。
  • 然后暴力打表出来发现OEIS找不到。而且数列6各一组很有规律,所以就写了打表A掉了
#include<iostream>
using namespace std;
int main(){
    int T;  cin>>T;
    while(T--){
        long long x;  cin>>x;
        if(x==1){ cout<<1<<'\n'; continue;}
        x-=1;
        long long t = x/6;
        if(x%6==1)cout<<t*3+1<<'\n';
        if(x%6==2)cout<<t<<'\n';
        if(x%6==3)cout<<3*(2*t+1)<<'\n';
        if(x%6==4)cout<<t<<'\n';
        if(x%6==5)cout<<3*(t+1)<<'\n';
        if(x%6==0)cout<<4*(t)+1<<'\n';
    }
    return 0;
}
posted @ 2019-08-17 20:30  gwj1139177410  阅读(109)  评论(0编辑  收藏  举报
选择