/*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. java实现 数据结构:链表、 栈、 队列、优先级队列、哈希表

    java实现 数据结构:链表. 栈. 队列.优先级队列.哈希表   数据结构javavector工作importlist 最近在准备找工作的事情,就复习了一下java.翻了一下书和网上的教材,发现虽然 ...

  2. react-native 框架升级 安卓第三方插件报错 Android resource linking failed

    亲自经历react-native从0.55升级到0.58的过程,有点坎坷,ios出现的问题还算不多,但是android这里,随着gradle和buildTool的使用升级,导致第三方插件出现各种问题, ...

  3. time | sys | os 模块,递归删除文件,项目分析

    一,复习 ''' 1.跨文件夹导包 - 不用考虑包的情况下直接导入文件夹(包)下的具体模块 2.__name__: py自执行 '__main__' | py被导入执行 '模块名' 3.包:一系列模块 ...

  4. windows枚举串口

    1. 枚举键值 HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM 2. SETUPAPI方式 int EnumPortsWdm() { int i, d ...

  5. ARM中的---汇编指令

    一. 带点的(一般都是ARM GNU伪汇编指令) 1. ".text".".data".".bss" 依次表示的是"以下是代码段& ...

  6. C++标准模板库 ——堆栈使用

    include using namespace std; stack S; S.push(i); S.pop(); int x = S.top(); ```

  7. Python文件处理(txt、csv文件读取)

    打开文件 使用Python内置的方法 open()可以打开文件 file object = open(file_name [, access_mode][, buffering]) file_name ...

  8. segv & mini coredump 调研

    1. mini coredump    a. segv      http://zh.scribd.com/doc/3726406/Crash-N-Burn-Writing-Linux-applica ...

  9. codevs1792 分解质因数

    题目描述 Description 编写一个把整数N分解为质因数乘积的程序. 输入描述 Input Description 输入一个整数 N 输出描述 Output Description 输出 分解质 ...

  10. openjudge1944 吃糖果

    描述名名的妈妈从外地出差回来,带了一盒好吃又精美的巧克力给名名(盒内共有 N 块巧克力,20 > N >0).妈妈告诉名名每天可以吃一块或者两块巧克力.假设名名每天都吃巧克力,问名名共有多 ...