// hdoj_1021 Fibonacci Again
/*
//通过找规律,发现
n 0 1 2 3 4 5 6 7 8 9 10
f(n) 7 11 18 29 47 76 123 199 322 521 843
余数 1 2 0 2 2 1 0 1 1 2 0
每8个数是一个循环,%8 == 2 和 &8 == 6的时候f(n)%3 == 0
*/
#include <stdio.h>
int main(void)
{
int n;
while(scanf("%d", &n) != EOF)
{
if(n % 8 == 2 || n % 8 == 6)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
/*这种做法是不对的,出现STACK_OVERFLOW (堆栈溢出) 栈溢出(又称缓冲区溢出)
#include <stdio.h>
int fun(int n);
int main()
{
int i, n;
while(scanf("%d", &n) && n < 1000000)
{
if(fun(n) % 3 == 0)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
int fun(int n)
{
if(n == 0)
return 7;
else if(n == 1)
return 11;
else
return fun(n-1) + fun(n-2);
}
*/
[热身题][hdoj_1021]Fibonacci Again
最新推荐文章于 2023-05-07 20:43:42 发布
本文深入分析了Fibonacci序列在特定余数条件下的特性,并提出了一种判断方法,通过循环周期性简化计算过程。此外,文章还讨论了递归函数在实现该方法时可能遇到的栈溢出问题及其解决方案。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
353

被折叠的 条评论
为什么被折叠?



