杭电oj~~1021
来源:互联网 发布:java supplier用法 编辑:程序博客网 时间:2024/05/16 09:55
尝试了很多办法,用打表,数组遍历都不行,要不超时要不数据溢出,最后想,利用求余运算,终于AC了。
题目描述:
Problem Description
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.
Print the word "no" if not.
Sample Input
012345
Sample Output
nonoyesnonono
AC代码:
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);while(in.hasNext()){int a,b,c,t=0,i;a = 7;b = 11;c = in.nextInt();if(c==0||c==1){System.out.println("no");}else{ for(i=2;i<=c;i++) {t = (a+b)%3;a = b%3;b = t%3; } if(t%3==0) {System.out.println("yes"); } else {System.out.println("no"); } } } }}
0 0
- 杭电oj~~1021
- 杭电oj-1021
- 杭电OJ--1021 Train Problem I
- 杭电OJ 1021 mod意识
- 杭电oj 题目1021Fibonacci Again
- 杭电oj分类
- 杭电oj
- 杭电OJ 2054
- 杭电OJ 1028
- 杭电 oj 1001
- 杭电OJ Elevator
- 杭电oj 1009
- 杭电oj-1003
- 杭电oj-1004
- 杭电oj-1005
- 饭卡 杭电oj
- 杭电OJ分类
- 杭电OJ 1002
- poj--3469--Dual Core CPU(最小割裸题)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault
- 布隆过滤器(Bloom Filter)Java实现
- JDBC数据库链接(MySQL数据库连接)
- sql语句进阶教程(学习sql这一篇就够了)
- 杭电oj~~1021
- A New Discrete-Time Iterative Adaptive Dynamic Programming Algorithm Based on Q-Learning
- swift开发网络篇—利用NSURLConnection GET请求和POST请求
- ~/.viminfo与~/.vinrc
- poj2886 Who Gets the Most Candies?(单点更新+约瑟夫环+素数打表)
- JavaScript对象的常用函数
- awk多维数组
- LeetCode---PowerOfTwo、PowerOfThree、 PowerOfFour解题分析
- 将两个单向有序链表合并成一个单向有序链表