/*Number Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 127146    Accepted Submission(s): 30901

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

Author

CHEN, Shunbao

Source

ZJCPC2004 

Recommend

JGShining   |   We have carefully selected several similar problems for you:  1008 1001 1003 1009 1012


*/

#include<stdio.h>

int main()

{

    int a,b,i;

    long long f[55],n;

    while(1)

    { scanf("%d %d %lld",&a,&b,&n);

        if(a==0&&b==0&&n==0)break;

        f[1]=f[2]=1;

        for(i=3;i<=49;i++)

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

        printf("%d\n",f[n%48]);

    }

    return 0;

}/*Number Sequence

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 127146 Accepted Submission(s): 30901

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

Author

CHEN, Shunbao

Source

ZJCPC2004

Recommend

JGShining | We have carefully selected several similar problems for you: 1008 1001 1003 1009 1012


*/

又一道找规律题目

#include<stdio.h>

int main()

{

int a,b,i;

long long f[55],n;

while(1)

{ scanf("%d %d %lld",&a,&b,&n);

if(a==0&&b==0&&n==0)break;

f[1]=f[2]=1;

for(i=3;i<=49;i++)

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

printf("%d\n",f[n%48]);

}

return 0;

}

HDUOJ Number Sequence 题目1005的更多相关文章

  1. Number Sequence(HDU 1005 构造矩阵 )

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. uva 10706 Number Sequence(数学规律)

    题目连接:10706 - Number Sequence 题目大意:有一个有0 ~ 9组成的序列,1   1 2    1 2 3   1 2 3 4   1 2 3 4 5 ....就是第一位为1. ...

  3. CF - 392 C. Yet Another Number Sequence (矩阵快速幂)

    CF - 392 C. Yet Another Number Sequence 题目传送门 这个题看了十几分钟直接看题解了,然后恍然大悟,发现纸笔难于描述于是乎用Tex把初始矩阵以及转移矩阵都敲了出来 ...

  4. HDU 1005 Number Sequence(数列)

    HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  5. 1005 Number Sequence(HDU)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 Number Sequence Time Limit: 2000/1000 MS (Java/O ...

  6. HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  9. HDU 1005 Number Sequence (模拟)

    题目链接 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f( ...

随机推荐

  1. [Python3网络爬虫开发实战] 2.5-代理的基本原理

    我们在做爬虫的过程中经常会遇到这样的情况,最初爬虫正常运行,正常抓取数据,一切看起来都是那么美好,然而一杯茶的功夫可能就会出现错误,比如403 Forbidden,这时候打开网页一看,可能会看到“您的 ...

  2. 源码学习-String类

    最近在扫描CodeDex时报了一个不能使用String.intern()的字符串来做锁对象的告警,对这个问题有疑问查了些资料,顺便学习一下String类的源码. 1.类定义 String 被final ...

  3. 常用的四种设计模式 PHP代码

    // 工厂模式 interface Iuser { public function getUserName(); } class UserFactory { static public functio ...

  4. PHP:GD库 生成验证码图片

    文章来源:http://www.cnblogs.com/hello-tl/p/7592998.html <?php /** * __construct($new):构造函数创建一张图片$new- ...

  5. 选项B中:int b[][3]={0,1,2,3}

    选项B中:int b[][3]={0,1,2,3};等价于 int b[][3]={0,1,2,3,0,0};    int b[][3]={0,1,2,3,4};         cout<& ...

  6. Quartz--Trigger

    TriggerQuartz中的触发器,用来告诉调度程序什么时候触发,即Trigger对象是用来触发Job的 触发器通用属性 JobKey StartTime EndTimeJobKey表示job实例的 ...

  7. 【BZOJ 1003】[ZJOI2006]物流运输(Dijkstra+DP)

    题链 http://www.lydsy.com/JudgeOnline/problem.php?id=1003 Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n ...

  8. CodeForcesGym 100212E Long Dominoes

    Long Dominoes Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on CodeForcesGym. ...

  9. 九度oj 题目1206:字符串连接

    题目1206:字符串连接 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:5117 解决:2373 题目描述: 不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来 ...

  10. CSU 1214 找最大异或值

    题目大意: 给定一堆数,从中找2个数异或得到的最大值 直接暴力会超时,我们要考虑对于每一个数去匹配找到异或的最大值,我们希望2进制越前面的数尽可能都为1 所以我们用 0-1 字典树保存这些数,因为一个 ...