URAL - 1860 Fiborial

Discription
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.

Example

Input:

   3

Output:

   4

 

 

     考虑每个数的贡献,发现一个数i 有 f(n-i) 中途径乘到F(n)里,所以F(n) = Π i * f(n-i)。

     至于再要求约数个数的话,我们只要再计算出每个质因子在最后这个大数中的次数就行了,一遍欧拉筛一遍统计就ojbk了。

 

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn=1000000,ha=1000000007;
int zs[maxn/10],t=0,F[maxn+5];
int ans=1,C[maxn+5],n;
struct node{ int d,c;};
vector<node> g[maxn+5];
bool v[maxn+5];
inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
inline int ksm(int x,int y){ int an=1; for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha; return an;}

inline void solve(){
	F[0]=F[1]=1;
	for(int i=2;i<=n;i++) F[i]=add(F[i-1],F[i-2]);
	
	for(int i=2;i<=n;i++){
		if(!v[i]) zs[++t]=i,g[i].pb((node){i,1});
		for(int j=1,u;j<=t&&(u=zs[j]*i)<=n;j++){
			v[u]=1;
			if(!(i%zs[j])){
				g[u]=g[i],g[u][0].c++;
				break;
			}
			g[u].pb((node){zs[j],1});
			for(int l=0,sz=g[i].size();l<sz;l++) g[u].pb(g[i][l]);
		}
	}
	
	for(int i=2,now;i<=n;i++){
		now=F[n-i]; node x;
		for(int j=g[i].size()-1;j>=0;j--){
			x=g[i][j];
			C[x.d]=add(C[x.d],x.c*(ll)now%ha);
		}
	}
	
	for(int i=2;i<=n;i++) if(C[i]) ans=ans*(ll)(C[i]+1)%ha;
}

int main(){
    scanf("%d",&n);
	solve();
	printf("%d\n",ans);
	return 0;	
}

  

转载于:https://www.cnblogs.com/JYYHH/p/8883695.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值