解题思路:
n=1,ans=1;n=2,ans=1;n=3,ans=2;n=4,ans=5……
ans 和 n 的关系满足n(1,2,……,N)->ans(1,1,3,5,8,13,……)//显然是斐波那契数列
注意事项:
mod7654321
参考代码:
#include <iostream>
int main(int argc, char const *argv[]) {
int n=0;
int x1=1,x2=1,x3=1;
int i=3;
std::cin >> n;
while ((n>2)&&(i<=n)) {//控制循环次数为n-2
x3=x1+x2;
x3%=7654321;//mod
x1=x2;
x2=x3;
i++;
}
std::cout << x3 << '\n';
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题12.6 (C语言代码)浏览:791 |
简单的a+b (C语言代码)浏览:520 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:742 |
简单的a+b (C++语言代码)浏览:852 |
母牛的故事 (C语言代码)浏览:915 |
【蟠桃记】 (C语言代码)浏览:664 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:1327 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:324 |
2006年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:661 |
震宇大神的杀毒软件 (C语言代码)浏览:1079 |