您的位置:首页 > 其它

hdu1005(规律)

2016-04-17 11:45 309 查看
Runtime Error(INTEGER_DIVIDE_BY_ZERO)代码:

#include <iostream>

#include <stdio.h>

#include <string.h>

#include <algorithm>

using namespace std;

int a,b,n,c;

int s[50005];

int main()

{

    while(~scanf("%d%d%d",&a,&b,&n)&&(a||b||n)){

        memset(s,0,sizeof(s));

        s[1]=s[2]=1;

        for(int i = 3; i < 10000; i++){

            s[i]=(a*s[i-1]+b*s[i-2])%7;

            if(s[i]==1&&s[i-1]==1){

                c=i-2;

                break;

            }

        }

        n%=c;

        if(n==0)

            printf("%d\n",s[c]);

        else

            printf("%d\n",s
);

    }

    return 0;

}

AC代码:

#include <iostream>

#include <stdio.h>

#include <string.h>

#include <algorithm>

using namespace std;

int a,b,n,c;

int s[50005];

int main(){

    while(~scanf("%d%d%d",&a,&b,&n)&&(a||b||n)){

        memset(s,0,sizeof(s));

        s[1]=s[2]=1;

        int i;

        for(i = 3; i < 10000; i++){

            s[i]=(a*s[i-1]+b*s[i-2])%7;

            if(s[i]==1&&s[i-1]==1){

                break;

            }

        }

        c=i-2;

        n%=c;

        if(n==0)

            printf("%d\n",s[c]);

        else

            printf("%d\n",s
);

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: