/*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. 20面向对象三特征 之继承 方法重写 super

    继承是:多个类有重复内容,把重复内容放到一个新类中,就可以通过extends关键词去让原来的类和新类产生继承关系,子类只能拿到父类一部分信息.通过extends关键词去指明类与类之间的关系,一个父类可 ...

  2. PHP 下基于 php-amqp 扩展的 RabbitMQ 简单用例 (二) -- Topic Exchange 和 Fanout Exchange

    Topic Exchange 此模式下交换机,在推送消息时, 会根据消息的主题词和队列的主题词决定将消息推送到哪个队列. 交换机只会为 Queue 分发符合其指定的主题的消息. 向交换机发送消息时,消 ...

  3. JVM优化(下)

    14.Tomcat8优化之G1牢记收集器的测试结果以及小结: jmeter测试:(1)tomcat未做任何优化:(2)禁用AJP:(3)启用连接池:(4)设置最大线程数1000,初始线程数200:(5 ...

  4. 制作framework&静态库

    http://blog.csdn.net/justinjing0612/article/details/7880712     (制作framework) http://blog.sina.com.c ...

  5. NOIP专题复习2 图论-生成树

    目录 一.知识概述 二.典型例题 1.口袋的天空 三.算法分析 (一)Prim算法 (二)Kruskal 四.算法应用 1.[NOIP2013]货车运输 五.算法拓展 1977: [BeiJing20 ...

  6. Layui框架 中table解决日期格式问题

    使用templet自定义模板(详细查看官方文https://www.layui.com)  1.对Date的扩展,将 Date 转化为指定格式的String ,创建一个js文件: (dataForma ...

  7. centos6 rpm安装mysql(5.5版本)包括 error : Failed dependencies:libaio的解决办法.

    1.先在/opt目录下放了两个rpm包 2.先看系统中是否有其他版本的mysql的rpm包 rpm -qa | grep -i mysql 命令结果如下图: 如果没有此步跳过,否则执行一下命令将其删除 ...

  8. python3.x Day5 subprocess模块!!

    subprocess模块: # subprocess用来替换多个旧模块和函数 os.system os.spawn* os.popen* popen2.* commands.* subprocess简 ...

  9. 选项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<& ...

  10. python Django 相关学习笔记

    Django框架 pip3 install django 命令: # 创建Django程序 django-admin startproject mysite # 进入程序目录 cd mysite # ...