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个中肯定会有至少一个重复,也就是循环周期了.当时没做出来,看的题解,重点是找出循环节
  1. #include<stdio.h>
  2. #include<math.h>
  3. int f(int a,int b,int n)
  4. {
  5. if(n==)
  6. return ;
  7. if(n==)
  8. return ;
  9. return (a*f(a,b,n-)+b*f(a,b,n-))%;
  10. }
  11. int main()
  12. {
  13. int a,b;
  14. int n;
  15. while(scanf("%d%d%d",&a,&b,&n)==)
  16. {
  17. if(a==b&&b==n&&n==)
  18. break;
  19. else
  20. printf("%d\n",f(a,b,n%));
  21. }
  22. }

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. QT---线程间通信(要先编译libqt-mt.so?)

    在 Qt 系统中,运行着一个GUI 主事件线程,这个主线程从窗口系统中获取事件,并将它们分发到各个组件去处理.在 QThread 类中有一种从非主事件线程中将事件提交给一个对象的方法,也就是 QThr ...

  2. WPF笔记(1.3 属性元素)——Hello,WPF!

    原文:WPF笔记(1.3 属性元素)--Hello,WPF! 这一节中“属性元素”的概念可以用匪夷所思形容.1.WPF用标签元素实现对象建模,有两种:Control和Container,都用来装载内容 ...

  3. linux命令行常用快捷键

    方向          <-前               后 ->删除ctrl + d      删除光标所在位置上的字符相当于VIM里x或者dlctrl + h      删除光标所在 ...

  4. 经典递归算法研究:hanoi塔的理解与实现

    关于hanoi塔的原理以及概念,请Google,访问不了去百度. 主要设计到C中程序设计中递归的实现: 主代码实现如下: void hanoi(int src, int dest, int tmp, ...

  5. C# Switch is Type

    常规用法: Type t = sender.GetType(); if (t == typeof(Button)) { var realObj = (Button)sender; // Do Some ...

  6. UESTC_邱老师的脑残粉 2015 UESTC Training for Graph Theory<Problem D>

    D - 邱老师的脑残粉 Time Limit: 12000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Sub ...

  7. UESTC_How many good substrings CDOJ 1026

    Icerain likes strings very much. Especially the strings only consist of 0 and 1,she call them easy s ...

  8. PKU 1050-To The Max(找矩形内元素最大和)

    Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous s ...

  9. 数字图像处理之sobel边缘检测

    在前两部文章介绍了几种边缘检测算法,和位图的内存结构.如果对前两篇文章已经理解透彻 了,那么本文将带你进入数字图像处理的世界. 本文通过C代码实现基本的sobel边缘检测,包括8个方向和垂直方向: 代 ...

  10. mongoDb c driver

    1,yum dependencies Centos,RHEL Fedora: $ sudo yum install git gcc automake autoconf libtool Debian: ...