hdu1005
来源:互联网 发布:mac触摸板怎么用 编辑:程序博客网 时间:2024/06/07 02:16
//两种方法,本以为会时间超限超限,就用数组将结果储存起来,没想到不用优化,直接ac了,判的有点松
#include <iostream>
using namespace std;
int A,B;
int f(int n)
{
if(n==1||n==2)
return 1;
else
return (A*f(n-1)+B*f(n-2))%7;
}
int main()
{
int n;
while(cin>>A>>B>>n&&(A||B||n))
cout<<f(n%49)<<endl;
/* int i;
for( i=3;i<10000;i++)
{
a[i] = (A*a[i-1] + B*a[i-2]) % 7;
if(a[i] == 1 && a[i-1] == 1)
break;
}
n = n % (i-2);
// 把n对周期求模,当n = i-2时, n=0,此时本来应该取arr[i-2]的,所以把arr[0]=arr[i-2]
//也可以这样:
//if(n==0) n=i-2;
a[0] = a[i-2];
cout << a[n] << endl;
}*/
return 0;
}
0 0
- HDU1005
- hdu1005
- hdu1005
- hdu1005
- HDU1005
- hdu1005
- HDU1005
- hdu1005
- hdu1005
- hdu1005
- HDU1005
- hdu1005
- HDU1005
- HDU1005
- HDU1005
- hdu1005
- hdu1005
- HDU1005
- 安卓小菜鸟重拾Java系列002.Java转义字符与与sax解析xml
- 多行文字溢出解决方案
- java编程思想读书笔记(四)
- django学习9 数据库操作命令
- 打印螺旋队列(更简单的方法)(难度:1颗星)
- hdu1005
- OJ题-营救公主
- 初译 Support Vector Machines:A Simple Tutorial(三)
- [NOI题库]7614:最低通行费
- 数组
- Go语言的实时GC原理和实践
- Excel VBA工作簿与工作表的操作
- 顾客是上帝(Keep the Customer Satisfied, ACM/ICPC SWERC 2005, UVa1153)
- Python解决两个整数相除只得到整数部分问题