posts - 99,  comments - 8,  trackbacks - 0
为啥少了一个else 就错了呢?
//显然数据范围非常的大,测试a[10000]时已经无法正确的表示了
//要用用相关的知识进行处理 : ( a + b ) % 3 = ( a % 3 + b % 3% 3
#include <stdio.h>
#
include <stdlib.h>
#
include <string.h>

int a[
1000009];

int main ()
{
    int n;
    a[0] 
= 7 % 3;
    a[
1= 11 % 3;  
    
for ( int i = 2; i < 1000009; i ++ )
    {
        a[i] 
= ( a[i - 1+ a[i - 2] ) % 3;
    }
    
    
while ( scanf ("%d"&n) != EOF )
    {
          
if ( !a[n] )
             printf (
"yes\n");
          
else
           printf (
"no\n");
    }
    
//system ("pause");
    
return 0;
}
posted on 2010-09-06 21:06 雪黛依梦 阅读(279) 评论(0)  编辑 收藏 引用 所属分类: 简单题数论

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年9月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜