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
 
除了f1 和f2以外,每个数字都由前两个数字决定,这个是公式确定的也就是说,如果对于数列f1 f2 ..fa fb .fc fd 存在fa=fc且fd=fb 那么后续的一定循环,对于任意的fn,由于是mod 7所以其取值只能是0 1 2 3 4 5 6这7种可能这样对于任意的连续两个数字,fa fb,可能的组合就是7*7=49种,而实际上,0,0序列是一个特殊的情况,除非A B都是7的倍数,那么所有序列都是0,不然是不会出现00的可能的.所以,如果提取一个长为50的任意子序列,可以提取出49个连续对,这49个中肯定会有至少一个重复,也就是循环周期了.当时没做出来,看的题解,重点是找出循环节
 #include<stdio.h>
#include<math.h>
int f(int a,int b,int n)
{
if(n==)
return ;
if(n==)
return ;
return (a*f(a,b,n-)+b*f(a,b,n-))%;
}
int main()
{
int a,b;
int n;
while(scanf("%d%d%d",&a,&b,&n)==)
{
if(a==b&&b==n&&n==)
break;
else
printf("%d\n",f(a,b,n%));
}
}

Number Sequence (HDoj1005)的更多相关文章

  1. ACM—Number Sequence(HDOJ1005)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 主要内容: A number sequence is defined as follows: f ...

  2. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  3. HDU 1005 Number Sequence(数列)

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

  4. Number Sequence(hdu4390)

    Number Sequence Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...

  5. HDU 1711 Number Sequence(KMP)附带KMP的详解

    题目代号:HDU 1711 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/ ...

  6. Number Sequence(kmp)

        Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 1005 Number Sequence(HDU)

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

  8. POJ - 1019 Number Sequence (思维)

    https://vjudge.net/problem/POJ-1019 题意 给一串1 12 123 1234 12345 123456 1234567 12345678 123456789 1234 ...

  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. POJ2485 最小生成树

    问题:POJ2485 本题求解生成树最大边的最小值 分析: 首先证明生成树最大边的最小值即最小生成树的最大边. 假设:生成树最大边的最小值比最小生成树的最大边更小. 不妨设C为G的一个最小生成树,e是 ...

  2. RenderPartial RenderAction Partial Action

    MVC Razor中有不同的展现partial view的方法,许多开发人员子在选择使用 RenderPartial or RenderAction or Partial or Action help ...

  3. 使用ARM模板部署自动扩展的Linux VMSS(2)

    12.准备完了模板文件,我们使用Powershell来创建VMSS for Linux的自动扩展集合,首先登陆到Azure中国的ARM账号: Login-AzureRmAccount -Environ ...

  4. SqlBulkCopy 类

    1.SqlBulkCopy 简介  Microsoft SQL Server 提供一个称为 bcp 的流行的命令提示符实用工具,用于将数据从一个表移动到另一个表(表既可以在同一个服务器上,也可以在不同 ...

  5. HttpContext请求上下文对象

    一.HttpContext概述 HttpContext基于HttpApplication的处理管道,由于HttpContext对象贯穿整个处理过程,所以,可以从HttpApplication处理管道的 ...

  6. javadoc 生成帮助文档时,注意以下几点

    参考:http://www.w3school.com.cn/tags/tag_pre.asp javadoc 生成帮助文档时,注意以下几点: 1.函数功能描述的结尾一定要有句号,英文句号或中文句号均可 ...

  7. 网易云课堂_C++开发入门到精通_章节7:模板

    课时35类模板 类模板 创建类模板的实例 class Name<类型参数表>object; 类模板与模板类的区别 类模板是模板的定义,不是一个实实在在的类,定义中用到通用类型参数 模板类是 ...

  8. IOS 打印网络请求全链接

    NSMutableString *urlStr = [NSMutableString stringWithFormat:@"%@?",request.URL]; ;i<[pa ...

  9. 具体解释EBS接口开发之物料导入API

    create_item inv_item_grp.create_item(p_commit => fnd_api.g_true, -- p_item_rec => l_item_rec, ...

  10. Hacker(五)----黑客专用通道--->端口

    计算机中,端口是计算机与外部进行通信交流的出口.计算机本身携带的物理端口(键盘.鼠标.显示器等输入/输出接口)已经无法满足网络通信的要求,因此TCP/IP协议就引入了一种称为Socket的应用程序接口 ...