URAL

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
",ans);
	return 0;	
}

  

原文地址:https://www.cnblogs.com/JYYHH/p/8883695.html