2019 百度之星初赛第一场 Seq

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6672

Problem Description
度度熊有一个递推式
在这里插入图片描述
其中 a1=1。现给出 n,需要求 an.

Input
第一行输入一个整数 T,代表 T (1≤T≤100000) 组数据。
接下 T 行,每行一个数字 n (1≤n≤1e12)。

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

Sample Input
5
1
2
3
4
5

Sample Output
1
1
0
3
0

这种题就是找规律,多写几个就能发现规律
我们先列举出部分

n123456789101112
an110303541916
n31415161718192021222324
an97215291310321312

由上述数据找出如下规律:6个数为一组

15913
14710
0123
391518
0123
36912

代码如下:

#include<iostream>
using namespace std;


int main()
{
	int n;
	long long int a;
	cin>>n;
	for(int i=0;i<n;i++){
        cin>>a;
        long long int num = a/6;
        if(a%6==1){
            cout<<4*num+1<<endl;
        }
        else if(a%6==2){
            cout<<3*num+1<<endl;
        }
        else if(a%6==3){
            cout<<num<<endl;
        }
        else if(a%6==4){
            cout<<num*6+3<<endl;
        }
        else if(a%6==5){
            cout<<num<<endl;
        }
        else if(a%6==0){
            cout<<3*num<<endl;
        }
	}
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值