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. python-matplotlib-lec1

    接演前文. 设置属性的方法: 使用对象的set_*方法,单独设置每个属性:或使用plt.setp同时设置多个属性 # -*- coding: utf-8 -*- import numpy as np ...

  2. linux学习-systemd-journald.service 简介

    过去只有 rsyslogd 的年代中,由于 rsyslogd 必须要开机完成并且执行了 rsyslogd 这个 daemon 之 后,登录文件才会开始记录.所以,核心还得要自己产生一个 klogd 的 ...

  3. selenium2设置浏览器窗口

    1.窗口最大化 //设置窗口最大化driver.manage().window().maximize(); 2.指定设置窗口大小 //指定呀设置窗口的宽度为:800,高度为600Dimension d ...

  4. 关于freetype在安装中的遇到的问题

    本人电脑配置的是Anconda环境+pycharm2017.2.2 comuniity,每次安装什么包就是直接pip install 的,但是这次在安装freetype的安装中却遇到了麻烦. 具体是在 ...

  5. 大数据学习——scala集合练习

    package com /** * Created by ZX on 2016/4/5. */ object ListTest { def main(args: Array[String]) { // ...

  6. 2018"百度之星"程序设计大赛 - 资格赛

    调查问卷  Accepts: 1546  Submissions: 6596  Time Limit: 6500/6000 MS (Java/Others)  Memory Limit: 262144 ...

  7. [错误处理]python大小写敏感,关键字不要写错

    今天调试程序,发现了一个极为隐蔽的bug. True False关键字大小写写错了,然后半天没找出问题所在.

  8. hdu6038[找规律+循环节] 2017多校1

    /*hdu6038[找规律+循环节] 2017多校1*/ #include<bits/stdc++.h> using namespace std; typedef long long LL ...

  9. kb-01-d<poj3279>--深搜变种,二进制优化;

    poj--3279 题意: 给n*m的矩阵,0 1组成,每次翻转一个格子可以将上下左右的五个节点翻转,求,把所有的格子翻转成0:输出每个个字的翻转次数:最少字数: 做法: 从上到下,第一行翻转的情况确 ...

  10. spring的事务传播与隔离

    propagation 事务的传播属性: 1.PROPAGATION_REQUIRED(*-required):支持当前事务,如果当前没有事务,就新建一个事务.(最常见的选择) 2.PROPAGATI ...