Fiborial


Description

Consider a sequence  F i that satisfies the following conditions:
Problem illustration
Find the number of different divisors of  F n.

Input

Input file contains the only integer number  n (1 ≤  n ≤ 10 6).

Output

Output the answer modulo 10 9 + 7.

Sample Input

input output
3
4



f[0] = f[1] = 1 ; f[i] = i * f[i-1] * f[i-2] ;求f[n]的因子个数。

以后看到这种f[n] = ...f[i-1] ... f[i-2]的类似表达式,一般还是联想到fibonacci比较靠谱。

 正解也就是fibonacci。

f[2] = 2 ;

f[3] = 2 * 3 ;

f[4] = 2 * 2 * 3 * 4 ;

f[5] = 2 * 2 * 2 * 3 * 3 * 4 * 5 

f[6] = 2 * 2 * 2 * 2 * 2 * 3 * 3 * 3 * 4 * 4 * 5 

每个因子的个数是1,2,3,5,8...这样增加的,直接用fibonacci就可以算出每个因子出现了多少次。

因为要求因子个数,所以合数要算成质因数的多少次幂。

这个在求prime的时候随便处理一下就可以了。。。



#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <cctype>
using namespace std;
const int M=1000000007;
bool p[1000002];
__int64 c[1000002];
__int64 f[1000002];
int main()
{
    __int64 n,i,j,k,l;

    __int64 ans;
    while(~scanf("%I64d",&n))
    {
        f[1]=f[2]=1;
        for(i=3; i<=n; i++)
            f[i]=(f[i-1]+f[i-2])%M;
        for(i=2; i<=n; i++)
        {
            if(p[i])continue;
            c[i]=f[n-i+1];
            j=i+i;
            while(j<=n)
            {
                p[j]=true;
                k=j;

                while(k%i==0)
                {
                    k=k/i;
                    c[i]=(c[i]+f[n-j+1])%M;
                }
                j=j+i;
            }

        }
        ans=1;
        for(i=2; i<=n; i++)
            ans=(ans*(c[i]+1))%M;
        printf("%I64d\n",ans);
    }

    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值