ZOJ Problem Set - 2060 Fibonacci Again
2015-01-27 20:33
423 查看
Fibonacci Again
Time Limit: 2 Seconds Memory Limit: 65536 KB
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2)
Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000)
Output
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
Sample Input
0
1
2
3
4
5
Sample Output
no
no
yes
no
no
no
Author: Leojay
Source: ZOJ Monthly, December 2003
分析:
题意:
有另一种斐波那契数列: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2)
输入包括多组测试数据。每一组测试数据只有一个整数n(n<1000000)。如果F(n)能被3整除,输出“yes”;否则输出“no”。
首先要知道被3整除是一个周期函数,然后多写几个n,推一下周期就可以了。找到规律直接ac
ac代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if((n-2)%4==0)
printf("yes\n");
else printf("no\n");
}
return 0;
}
Time Limit: 2 Seconds Memory Limit: 65536 KB
There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2)
Input
Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000)
Output
Print the word "yes" if 3 divide evenly into F(n).
Print the word "no" if not.
Sample Input
0
1
2
3
4
5
Sample Output
no
no
yes
no
no
no
Author: Leojay
Source: ZOJ Monthly, December 2003
分析:
题意:
有另一种斐波那契数列: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2)
输入包括多组测试数据。每一组测试数据只有一个整数n(n<1000000)。如果F(n)能被3整除,输出“yes”;否则输出“no”。
首先要知道被3整除是一个周期函数,然后多写几个n,推一下周期就可以了。找到规律直接ac
ac代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if((n-2)%4==0)
printf("yes\n");
else printf("no\n");
}
return 0;
}
相关文章推荐
- ZOJ Problem Set - 1709 Oil Deposits
- ZOJ Problem Set - 1712||Skew Binary
- ZOJ Problem Set - 1008 Gnome Tetravex (TLE)
- ZOJ Problem Set - 2186 Keep on Truckin'
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 3827Information Entropy
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 3418 Binary Number
- ZOJ Problem Set–2417 Lowest Bit
- ZOJ Problem Set - 3938 (模拟)
- ZOJ Problem Set - 3938 Defuse the Bomb
- ZOJ Problem Set - 2100
- ZOJ Problem Set - 3811 Untrusted Patrol
- ZOJ Problem Set–1879 Jolly Jumpers
- ZOJ Problem Set - 2186 Keep on Truckin'【模拟】
- ZOJ Problem Set–2405 Specialized Four-Digit Numbers
- ZOJ Problem Set - 3795(缩点拓补)
- ZOJ Problem Set - 3643 Keep Deleting
- ZOJ Problem Set - 1512 (Water Treatment Plants)
- ZOJ Problem Set - 1002 Fire net