URAL - 1860 Fiborial
Input
Output
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的更多相关文章
- POJ 1860(spfa)
http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- 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 ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
随机推荐
- python多进程并发进程池Pool
简介: python中的多进程主要使用到 multiprocessing 这个库.低版本python这个库在使用 multiprocessing.Manager().Queue时会出问题,建议大家升级 ...
- leetcode-16-greedyAlgorithm
455. Assign Cookies 解题思路: 先将两个数组按升序排序,然后从后往前遍历,当s[j] >= g[i]的时候,就把s[j]分给g[i],i,j都向前移动,count+1;否则向 ...
- poj 1995 快速幂
题意:给出A1,…,AH,B1,…,BH以及M,求(A1^B1+A2^B2+ … +AH^BH)mod M. 思路:快速幂 实例 3^11 11=2^0+2^1+2^3 => 3^1*3 ...
- 如何生成带注释的DLL文件
背景: 实际上并不是生成带有注释的DLL文件,而是同时生成一个XML文件,用来显示注释. 为什么要使用DLL文件,在C#编程的过程中,一直在使用DLL文件,如System.dll 方法: 1,创建类库 ...
- HTML中块级元素和行内元素的总结和区分。
HTML标签 html标签定义: 是由一对尖括号包裹的单词构成,例如: <html>. 标签不区分大小写<html> 和 <HTML>, 推荐使用小写. 标签分为两 ...
- 《Scrum实战》第2次课【取得大家的支持】课后作业汇总
作业:<变革之心>读后感 孟帅: 2017-7-12http://www.cnblogs.com/mengshuai1982/p/7153985.html
- windows基本DOS命令
基本命令 dir : 列出当前目录下的文件以及文件夹,后面可以接其他路径 md : 创建目录(mkdir),一次创建多级目录,mkdir a\b\c rd : 删除目录,删除非空目录rd /s(删除最 ...
- Flowerpot(单调队列)
描述 Farmer John has been having trouble making his plants grow, and needs your help to water them pro ...
- The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online
A Live Love DreamGrid is playing the music game Live Love. He has just finished a song consisting of ...
- mysql使用日常备忘
批量插入数据时,如果主键是有业务意义的,并非自自增张,那么有可能在插入的数据中有与已存在的键值重复的,可以用如下方式来插入: INSERT IGNORE 当要插入一个数据时,插入的字段值中主键字段或唯 ...