百度之星初赛一--Seq--打表

Seq

Accepts: 1283

Submissions: 3956

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

Problem Description

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

Input

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

Output

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

Sample Input

Copy

5
1
2
3
4
5

Sample Output

Copy

1
1
0
3
0

打表代码


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define ll long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
//priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 100000+66;
const ll INF =1e18+2;
int n,k;
int a[maxn];
int main()
{
    a[0]=0;
    a[1]=1;
    int n;
    n=10000000;
    for(int i=1;i<=10000;i++)
    {
        for(int j=1;j<=i-1;j++)
        {
            a[i]+=a[j]*j%i;
            a[i]%=i;
        }
        if(i%2==1)cout<<"a "<<i<<"====="<<a[i]<<endl;
    }
    return 0;
}

然后会发现偶数和奇数的规律:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5e5+5;
LL n;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&n);
        if(n%2==0)
        {
            if(n<4)
            {
                cout<<n/2<<endl;
            }
            else if((n-4)%6==0)
            {
                cout<<n-1<<endl;
            }
            else
            {
                cout<<n/2<<endl;
            }
        }
        else
        {
            if((n-1)%6==0)
			{
				cout<<(n-1)/6*4+1<<endl;
			}
			else
			{
				if((n-3)%6==0)
				{
					cout<<(n-3)/6<<endl;
				}
				else
				{
				cout<<(n-5)/6<<endl;
				}
			}
        }
    }

    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值