HDoj 1005
来源:互联网 发布:用友软件武汉公司 编辑:程序博客网 时间:2024/05/20 11:50
Number Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104083 Accepted Submission(s): 25200
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).
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 31 2 100 0 0
Sample Output
25
#include<cstdio>int fun(int a,int b,int n){ if(n==1||n==2) return 1; else return (a*fun(a,b,n-1)+b*fun(a,b,n-2))%7;}int main(){ int a,b,n; while(scanf("%d %d %d",&a,&b,&n),(a+b+n)) { printf("%d\n",fun(a,b,n%49)); } return 0;}
0 0
- hdoj 1005
- HDOJ 1005
- HDOJ 1005
- HDoj 1005
- HDOJ 1005
- HDOJ 1005
- HDOJ--1005
- HDOJ 1005
- HDOJ 1005
- hdoj 1005
- HDOJ 1005 : Number Sequenc
- HDOJ 1005 Number Sequence
- 【HDOJ】1005 -> Number Sequence
- HDOJ 1005 Number Sequence
- HDOJ 1005 Number Sequence
- 【hdoj 1005】有限状态机
- HDOJ 1005:吃糖果
- hdoj 1005 NUMBER Sequence
- STL有6种序列容器(vector, list, deque, queue, priority_deque, stack)
- Android UI--自定义ListView(实现下拉刷新+加载更多)
- Android学习路线(二十六)Android数据存储
- STL有4种联合容器(set,multiset, map, multimap)
- jquery制作美化星星评分插件
- HDoj 1005
- STL 之 set
- 「斜」italics() //使用斜体显示字符串 20140817 ①文本处理
- Android学习路线(二十七)键值对(SharedPreferences)存储
- LeetCode-Reverse Nodes in k-Group
- 在内嵌RAM中运行程序 No Algorithm found for 错误
- 利用非循环顺序队列采用广度搜索法求解迷宫问题(一条路径)
- Android UI【android 仿微信、QQ聊天,带表情,可翻页,带翻页拖动缓冲】
- www.qdmm.com/BookReader/3263379,57819005.aspx