妖三欺


私信TA

用户名:s237834893

访问量:5387

签 名:

代码千万行,注释第一行

等  级
排  名 2442
经  验 2211
参赛次数 0
文章发表 17
年  龄 0
在职情况 学生
学  校 哈尔滨工程大学
专  业

  自我简介:

#include <stdio.h>
#include <math.h>
long sum(long x)
{
    long a[10000];
    a[0]=1;
    a[1]=1;
    for(int i=2;i<x;i++)
    {
        a[i]=(a[i-1]+a[i-2])%7654321;
    }
    return a[x-1];
}
int main()
{
    long x;
    scanf("%d",&x);
    if(x==1) {printf("%d",1);return 0;}
    else printf("%d\n",sum(x));
}


参考代码:

#include <stdio.h>
int sum(long x,int n)
{
    if(n==0||n==1) return 0;
    if(x==1&&n==2) return 1;
    if(x==2&&n==2) return 1;
    if(x==3&&n==2) return 2;
    if(x==4&&n==2) return 2;
    if(x==1) return sum(3,n-1);
    if(x==2) return sum(4,n-1);
    if(x==3) return sum(1,n-1)+sum(4,n-1);
    if(x==4) return sum(3,n-1)+sum(2,n-1);
}
int main()
{
    long x;
    scanf("%d",&x);
    if(x==1) {printf("%d",1);return 0;}
    else printf("%d\n",sum(1,x)%7654321);
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区