码迷,mamicode.com
首页 > 其他好文 > 详细

NowCoder数列

时间:2017-12-30 17:10:23      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:algorithm   https   stream   using   pos   .com   pre   names   term   

题目:https://www.nowcoder.com/questionTerminal/0984adf1f55a4ba18dade28f1ab15003

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 const int maxn = 1000000 + 5;
 6 int f[maxn];
 7 
 8 void db(){
 9     f[0] = 7 % 3;
10     f[1] = 11 % 3;
11     for (int i = 2; i < maxn; i++){
12         f[i] = (f[i - 1] + f[i - 2]) % 3;
13     }
14 }
15 
16 int main(){
17     db();
18     int n;
19     while (cin >> n){
20         if (f[n] == 0){
21             cout << "Yes" << endl;
22         }
23         else{
24             cout << "No" << endl;
25         }
26     }
27 //    system("pause");
28     return 0;
29 }

 

NowCoder数列

标签:algorithm   https   stream   using   pos   .com   pre   names   term   

原文地址:https://www.cnblogs.com/jaydenouyang/p/8150081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!