HDU 1005 Number Sequence
2016-03-17 19:25
471 查看
找规律
结果一定会循环 当出现0 1 1 时就是一个循环 后面的数据会和前面的一样
结果一定会循环 当出现0 1 1 时就是一个循环 后面的数据会和前面的一样
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { freopen("C:\\CODE\\in.txt", "r", stdin); //freopen("C:\\CODE\\out.txt","w",stdout); int A,B,n; int a[100]={0}; a[0]=0;a[1]=a[2]=1; while(~scanf("%d%d%d",&A,&B,&n)) { if(A+B+n == 0) break; int i; for(i=3;i<100;i++){ a[i]=(A*a[i-1]+B*a[i-2])%7; if(a[i]==a[i-1] && a[i]==1) break; } i=i-2; n=n%i; if(n == 0) n=i; //若没有这句,会错误 printf("%d\n",a ); } fclose(stdin); return 0; }
相关文章推荐
- 再也不用管UIImagePicker的代理了
- IOS控件学习之UIScrollView(2)
- 项目:BluetoothChat
- 1570: [JSOI2008]Blue Mary的旅行 最大流
- [Android M] Bluedroid修改蓝牙默认名称
- UI设计师未来的4个发展方向
- IOS控件学习之UIScrollView(1)
- iOS UIImage 异步加载 图片缓存压缩 UIImageVIew分类
- POJ 2031 Building a Space Station(最小生成树)
- Handler、Message、MessageQueue、 Looper、Handler Thread
- POJ - 2533 Longest Ordered Subsequence(最长上升子序列)
- sublime3 build3103版本 注册码 能用最新
- easyui validatebox 验证类型
- The project 'FeiYueXueTang_Android' may be using a version of Gradle that does not contain the metho
- setValue:ForKeyPath
- request.getParameterMap()返回的Map详解
- UICollectionView
- 160317(一)、在非action中获取request
- MySql.Data.Entity 在EF中解析uint的枚举时有BUG
- iOS开发UI篇—核心动画(基础动画)