hdu3054(斐波那契。。。。找规律)
来源:互联网 发布:mac把图标放在桌面 编辑:程序博客网 时间:2024/06/03 21:31
Problem Description
We know the Fibonacci Sequence
F1=1,F2=1,F3=2,F4=3,F5=5,
...
Fx = Fx-1+Fx-2
We want to know the Mth number which has K consecutive "0" at the end of Fx.
For example,
F15=610
It is the first number which has only one "0" at the end.
F300=222232244629420445529739893461909967206666939096499764990979600.
It is the second number which has two "0" at the end.
Of course, the Fx may be very large if M and K are big. So we only want to know the subscript of Fx (it means the "x" For a given M and K)
F1=1,F2=1,F3=2,F4=3,F5=5,
...
Fx = Fx-1+Fx-2
We want to know the Mth number which has K consecutive "0" at the end of Fx.
For example,
F15=610
It is the first number which has only one "0" at the end.
F300=222232244629420445529739893461909967206666939096499764990979600.
It is the second number which has two "0" at the end.
Of course, the Fx may be very large if M and K are big. So we only want to know the subscript of Fx (it means the "x" For a given M and K)
Input
Input includes multiple cases.
First line is the number of case x
The next x lines: Each line contains two integer number, K and M, divided by a space.
First line is the number of case x
The next x lines: Each line contains two integer number, K and M, divided by a space.
Output
For each case:
Print a integer number in a line, is the Mth number which has K consecutive 0s at the end of Fx. (You can believe the answer is smaller than 2^31);
Print a integer number in a line, is the Mth number which has K consecutive 0s at the end of Fx. (You can believe the answer is smaller than 2^31);
Sample Input
31 12 22 5
Sample Output
15300900
打表。。。。这题代码量比较少,但还是很考验找规律能力的,而且!!!
眼力必须好啊!
下面是我的打表代码,输入n代表末尾n个0:
#include <iostream>using namespace std;int pp(int n){ int ans=1; for(int i=0;i<n;i++) ans*=10; return ans;}int f[100000000]={0};int main(){ int n; while(cin>>n) { int p0=pp(n),p1=pp(n+1),t=1; f[1]=1; for(int i=2;i<100000000;i++) { f[i]=(f[i-1]+f[i-2])%p1; if(f[i]%p0==0&&f[i]!=0) { cout<<i<<"th feibo "<<t++<<"th number"<<endl; } if(t==50)break; } } return 0;}
运行完打表代码之后会发现1,3,4,5,6,7,……都是到第9个数增量是有一个变化!
而2是到第4个数增量有了变化!(说实话真的很难仔细一直看到第9个!!能看出2都很不错了)
然后就是找规律了,这个自己都能写的!
#include <iostream>#include <stdio.h>#include<string.h>using namespace std;int pp(int n){ int ans=1; for(int i=0;i<n;i++) ans*=10; return ans;}int main(){ int t; scanf("%d",&t); while(t--) { int k,m; scanf("%d%d",&k,&m); if(k==1) { printf("%d\n",15*(((m-1)/9)*10+1)+15*((m-1)%9)); } else if(k==2) { printf("%d\n",150*((m-1)/4*5+1)+150*((m-1)%4)); } else { printf("%d\n",75*pp(k-2)*(((m-1)/9)*10+1)+75*pp(k-2)*((m-1)%9)); } } return 0;}
0 0
- hdu3054(斐波那契。。。。找规律)
- 数学- 找规律 HDU3054
- 51nod-斐波那契表示(找规律)
- hdu1021新版斐波那契避免超时找规律
- hdu 1021 斐波那契2,找规律
- 找规律 51Nod1350 斐波那契表示
- nefu 115 斐波那契的整除 找规律
- 51nod1350 斐波那契表示 找规律+递归
- hpuoj【1444】斐波那契数列&& 【找规律】
- HDU 5914 Triangle【斐波那契 找规律】
- HDU 5620 KK's Steel(找规律,斐波那契数列的应用)
- 找规律,数学(巨大的斐波那契数列,uva 11582)
- UVa Live-3357 Pinary(斐波那契+找规律)
- 51nod 1350 斐波那契表示(打表+找规律)
- HDU 4549 M斐波那契数列 (找规律+矩阵快速幂+数快速幂)
- 51NOD 1491 黄金系统 && Codeforces 458 A. Golden System(斐波那契数列 + 找规律)
- Codeforces Round #382 (Div. 2) -- C. Tennis Championship (数学找规律 -- 斐波那契数列)
- hdu2516 取石子游戏-----找规律 必败点---斐波那契数列
- SGU106 The equation(数论)
- Android基础 学习之List 和 Adapter
- 关于pow函数。
- jQuery 的选择器
- C++之单例模式
- hdu3054(斐波那契。。。。找规律)
- pazu使用指南
- OC的手动内存管理
- Android UI 优化方向
- 0910Android基础MediaPlayer
- 剑指Offer系列---(17)调整数组顺序使奇数位于偶数前面
- 仅用O(1)的空间,将整数数组按奇偶数分成2部分,数组左边是奇数、右边是偶数
- UITableView 基础知识
- eclipse中maven项目交付svn忽略配置文件