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 ...
随机推荐
- 打印机增强软件pdfpro
http://3dx.pc6.com/gm1/pdfpro.zip
- Linux学习-核心的编译与安装
编译核心与核心模块 核心与核心模块需要先编译起来,而编译的过程其实非常简单,你可以先使用『 make help 』去查 阅一下所有可用编译参数, 就会知道有底下这些基本功能: [root@study ...
- luogu1742 最小圆覆盖
狗题卡我精度--sol #include <algorithm> #include <iostream> #include <cstdlib> #include & ...
- 反射的妙用-类名方法名做参数进行方法调用实例demo
首先声明一点,大家都会说反射的效率低下,但是大多数的框架能少了反射吗?当反射能为我们带来代码上的方便就可以用,如有不当之处还望大家指出 1,项目结构图如下所示:一个ClassLb类库项目,一个为测试用 ...
- webdriver高级应用- 使用日志模块记录测试过程中的信息
在自动化脚本执行过程中,使用Python的日志模块记录在测试用例执行过程中一些重要信息或者错误日志等,用于监控和后续调试脚本. 在pycharm下新建工程,并创建Log.py.Logger.conf以 ...
- 聊聊、Java Keytool P12 转 JKS
最近公司合作机构需要更改服务证书,总共给了 3 个文件过来.openapi-cert.p12.openapi-cert.key.openapi-cert.crt. openapi-cert.crt - ...
- TOJ1196: RSA Signing
题不在多,大概是多了也可能就是菜逼 1196: RSA Signing Time Limit(Common/Java):3000MS/30000MS Memory Limit:65536KBy ...
- The 18th Zhejiang University Programming Contest Sponsored by TuSimple
Pretty Matrix Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid's birthday is coming. As hi ...
- 使用MySQLWorkBench连接数据库
在日常使用中,经常使用命令行去连接MySQL数据库不方便,推荐使用MySQLWorkBench去远程连接进行管理,下面记录一下使用步骤: 1. 安装MySQLWorkBench后,界面如下,点击“+” ...
- 九度oj 题目1460:Oil Deposit
题目描述: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...