hdu 3054 Fibonacci 找循环节的公式题

Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)


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)
 

 

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.
 

 

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);
 

 

Sample Input
3 1 1 2 2 2 5
 

 

Sample Output
15 300 900
 

 

Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+10,M=4e6+10,inf=1e9+10,MOD=1000;
const ll INF=1e18+10;
int a[100]={1,15,150,750,7500,75000,750000,7500000,75000000,750000000};
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int k,m;
        scanf("%d%d",&k,&m);
        if(k==2)
            printf("%d\n",((m-1)/4*5+1)*a[k]+((m-1)%4)*a[k]);
        else
            printf("%d\n",((m-1)/9*10+1)*a[k]+((m-1)%9)*a[k]);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/jhz033/p/6005689.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值