| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 967 人关注过本帖
标题:hdu1005说运行时错误 为什么啊 求原因
取消只看楼主 加入收藏
末日泡沫
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2015-3-1
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:3 
hdu1005说运行时错误 为什么啊 求原因
Problem Description
A number sequence is defined as follows:

f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.

Given A, B, and n, you are to calculate the value of f(n).

Input
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.

Output
For each test case, print the value of f(n) on a single line.

Sample Input
1 1 3
1 2 10
0 0 0
 
Sample Output
2
5

#include<stdio.h>
#include<math.h>
int main()
{
    int a,b;
    long long n;
    long long c[1000];
    int d;
    while(scanf("%d %d %lld",&a,&b,&n)==3)
    {
        c[1]=1;
        c[2]=1;
        for(d=3;d<=n;d++)
        {
            c[d]=(b*c[1]+a*c[2]);
            c[1]=c[2];
            c[2]=c[d];
        }
        if(a==0&&b==0&&n==0)
        break;
        printf("%lld\n",c[2]%7);
    }
    return 0;
}
搜索更多相关主题的帖子: multiple sequence number single 
2015-03-03 16:03
末日泡沫
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2015-3-1
收藏
得分:0 
回复 2楼 azzbcc
那要怎么修改呢?
2015-03-03 17:27
末日泡沫
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2015-3-1
收藏
得分:0 
回复 5楼 longwu9t
谢谢 我得好好消化一下你的代码
2015-03-04 10:07
末日泡沫
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2015-3-1
收藏
得分:0 
回复 10楼 wmf2014
设定大数组 比如long long a[]这样的 是不是不符合规定的?
2015-03-04 14:03
快速回复:hdu1005说运行时错误 为什么啊 求原因
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011971 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved