hdu1005 Number Sequence
来源:互联网 发布:php class 魔术方法 编辑:程序博客网 时间:2024/06/07 09:46
题目链接:点击打开链接
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
ps:这个题是个有循环结果的,以48为周期循环(循环结果的题型)
#include <iostream>#include<cstdio>using namespace std;int main(){ int n; int a,b; int f1=1,f2=1,f; while(scanf("%d%d%d",&a,&b,&n)) { if(a==0&&b==0&&n==0)break; f1=f2=1; if(n%48!=0) { if(n%48<=2) { cout<<f1<<endl; continue; } for(int i=3; i<=n%48; i++) { f=(a*f2+b*f1)%7; f1=f2; f2=f; } } else { for(int i=1; i<=48; i++) { f=(a*f2+b*f1)%7; f1=f2; f2=f; } } cout<<f<<endl; } return 0;}
0 0
- Number Sequence hdu1005
- (hdu1005)Number Sequence
- hdu1005 Number Sequence
- hdu1005 number sequence
- hdu1005 Number Sequence
- hdu1005 ( Number Sequence )
- Number Sequence(HDU1005)
- hdu1005 Number Sequence(数论)
- hdu1005 Number Sequence
- HDU1005 Number Sequence
- Hdu1005 Number Sequence
- hdu1005 Number Sequence
- hdu1005 Number sequence(数学)
- HDU1005 Number Sequence
- hdu1005 Number Sequence
- Number Sequence(HDU1005)
- HDU1005 Number Sequence
- hdu1005 Number Sequence
- ios开发笔记之十四--用代码来监听按钮的点击
- 第10-11周项目:继承与派生
- RGB颜色表
- WindowManager.LayoutParams.type属性
- TCP为什么需要3次握手与4次挥手
- hdu1005 Number Sequence
- 关于Extjs翻页问题解决
- Hibernate中的即时加载
- BeanNameAware接口和BeanFactoryAware接口
- nohup
- 关于JDialog中添加组件无法显示的问题
- Linux下Tomcat的启动、关闭、杀死进程
- Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]解决办法
- TcpFlow(1.4.6 C++版本)源代码分析之以太网数据包处理,ip数据包处理