/*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. VC++检测硬件设备状态

    首先捕捉WM_DEVICECHANGE消息,该消息在usb插拔时均有触发. MFC下 添加消息处理函数afx_msg BOOL OnDeviceChange( UINT nEventType, DWO ...

  2. gprc-java与golang分别实现服务端,客户端,跨语言通信(一.java实现)

    1.在pom中引入 <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty< ...

  3. 基于Docker Compose搭建mysql主从复制(1主2从)

    系统环境 * 3 Ubuntu 16.04 mysql 8.0.12 docker 18.06.1-ce docker-compose 1.23.0-rc3 *3 ==> PS  ###我用的是 ...

  4. vsftp虚拟用户方式访问

    需求:外部人员需要对公司服务器上某个文件夹内容进行读写操作 文件目录信息:/opt/abc drwxr-xr-x 9 www  www       4096 12月  4 13:02 abc   #注 ...

  5. Try, throw和catch用法

    PHP 5 提供了一种新的面向对象的错误处理方法. 使用思路如下: 1.Try - 使用异常的函数应该位于 "try" 代码块内.如果没有触发异常,则代码将照常继续执行.但是如果异 ...

  6. [Python3网络爬虫开发实战] 1.2.2-Selenium的安装

    Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作.对于一些JavaScript渲染的页面来说,这种抓取方式非常有效.下面我们来看看Selenium的安装 ...

  7. python爬虫入门01:教你在 Chrome 浏览器轻松抓包

    通过 python爬虫入门:什么是爬虫,怎么玩爬虫? 我们知道了什么是爬虫 也知道了爬虫的具体流程 那么在我们要对某个网站进行爬取的时候 要对其数据进行分析 就要知道应该怎么请求 就要知道获取的数据是 ...

  8. cookie、localStorage和sessionStorage三者的异同

    1.三者都是用来存储浏览器数据的 2.生命周期:cookie可以设置数据失效时间,默认是关闭浏览器后失效:localStorage中的数据是永久保存的,除非手动清除:sessionStorage的数据 ...

  9. Thawte SSL Web Server 多域型SSL证书

    Thawte SSL Web Server 多域型SSL证书,最多支持25个域名,需要验证域名所有权和申请单位信息,属于企业验证型SSL证书,提供40位/56位/128位,最高支持256位自适应加密. ...

  10. Mysql学习总结(43)——MySQL主从复制详细配置

    环境 操作系统:CentOS-6.6-x86_64-bin-DVD1.iso MySQL版本:mysql-5.6.26.tar.gz 主节点IP:192.168.1.205 主机名:edu-mysql ...