Discription
Consider a sequence F i that satisfies the following conditions: 
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;
}

  

URAL - 1860 Fiborial的更多相关文章

  1. POJ 1860(spfa)

    http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...

  2. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  3. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  4. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  5. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  6. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  7. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  8. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  9. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

随机推荐

  1. city Engine 建模

    基本操作介绍 界面布局,文件组织 五个常见图层 常见规则,替换思想

  2. PAT Basic 1079

    1079 延迟的回文数(20 分) 给定一个 k+1 位的正整数 N,写成 a​k​​⋯a​1​​a​0​​ 的形式,其中对所有 i 有 0≤a​i​​<10 且 a​k​​>0.N 被称 ...

  3. HDU 3488 KM Tour

    参考题解 这题注意有重边.. #include <cstdio> #include <cstring> #include <algorithm> using nam ...

  4. luogu2053 [SCOI2007]修车

    把m个师傅拆成n个阶段,考虑每个人选上第某个阶段的某师傅对答案做出的贡献. 参见这里与那里. #include <iostream> #include <cstring> #i ...

  5. Mysql 安装及MySQL-python 问题

    今天遇到了个低级问题: EnvironmentError:mysql_config not found 网上谷歌了一圈发现没用,静下来想的时候才发现新电脑没安装Mysql,吐血 后面再去官网上下载My ...

  6. Get Sauce(状压DP)

    描述 In order to celebrate the 8th anniversary of ZOJ, LCLL goes to a sauce factory to "Get Sauce ...

  7. [笔记]Docker解决了什么问题?

    Docker的优势: 环境依赖问题 更轻量的虚拟化,节省了虚拟机的性能损耗 Docker应用场景: 程序分发,gitlab的安装很恶心吧,所以有人做了gitlab的image 部署发布,这点对运维的同 ...

  8. javascript学习笔记 - 引用类型 Array

    二 Array 1.可以通过length属性删除或创建新的数组项 arr = [1,2,3]; arr.length = 4;//增加 [1,2,3,undefined] arr.length = 2 ...

  9. Oracle 用户和权限

    Oracle 用户和权限Oracle 中,一般不会轻易在一个服务器上创建多个数据库,在一个数据库中,不同的项目由不同的用户访问,每一个用户拥有自身创建的数据库对象,因此用户的概念在 Oracle中非常 ...

  10. C#发送邮件异常,返回信息乱码

    发邮件时出现了异常: 在 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) 在 ...