题目概述
令斐波那契数列第0个数为7,第1个数为11,问第a个斐波那契数是否能被3整除
时限
1000ms/2000ms
输入
每行一个正整数a,输入到EOF结束
限制
2<=a<=1e6
输出
每行一个输出,如果能整除,输出yes,否则no
样例输入
0
1
2
3
4
5
样例输出
no
no
yes
no
no
no
讨论
感觉这题改成问a-2能否被4整除就比较简单了,往往做数论的题,看到有如此大的数据规模和这么短的时限,要么有公式,要么有规律,没错,开long long一个个试,到a=87之前还都不会溢出,也足以看出规律了
题解状态
0MS,1712K,412 B,C++
题解代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define MAXN 22
#define memset0(a) memset(a,0,sizeof(a))
#define llong long long
int main(void)
{
//freopen("vs_cin.txt", "r", stdin);
//freopen("vs_cout.txt", "w", stdout);
int a;
while (~scanf("%d", &a)) {//input
if ((a - 2) % 4 == 0)
printf("yes\n");//output
else
printf("no\n");//output
}
}
EOF