51nod 1189 阶乘分数(分解质因数)
来源:互联网 发布:informatica linux 编辑:程序博客网 时间:2024/05/16 13:50
1189 阶乘分数
题目来源: Spoj
基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
收藏 关注
1/N! = 1/X + 1/Y,给出N,求满足条件的整数解的数量。例如:N = 2,1/2 = 1/3 + 1/6,1/2 = 1/4 + 1/4。由于数量可能很大,输出Mod 10^9 + 7。
Input
输入一个数N(1 <= N <= 1000000)。
Output
输出解的数量mod 10^9 + 7。
Input示例
2
Output示例
2
两边同时加上
之后只要对
把1到N的每个数的质因子都找出来
AC代码如下:
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <sstream>#include <cstdlib>#include <iostream>#include <algorithm>#pragma comment(linker,"/STACK:102400000,102400000")using namespace std;#define MAX 1000005#define MAXN 1000005#define maxnode 15#define sigma_size 30#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define LL long long#define ull unsigned long long#define mem(x,v) memset(x,v,sizeof(x))#define lowbit(x) (x&-x)#define pii pair<int,int>#define bits(a) __builtin_popcount(a)#define mk make_pair#define limit 10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f;const double pi = acos(-1.0);const double inf = 1e18;const double eps = 1e-8;const LL mod = 1e9+7;const ull mx = 133333331;/*****************************************************/inline void RI(int &x) { char c; while((c=getchar())<'0' || c>'9'); x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; }/*****************************************************/bool prime[MAX];int pr[MAX];int tot;int vis[MAX];void init(){ mem(prime,0);tot=0; for(int i=2;i<MAX;i++){ if(!prime[i]) pr[tot++]=i; for(int j=0;j<tot&&pr[j]*i<MAX;j++){ prime[i*pr[j]]=1; if(i%pr[j]==0) break; } }}LL qpow(LL a,LL n){ LL ans=1; while(n){ if(n&1) ans=ans*a%mod; a=a*a%mod; n>>=1; } return ans;}int main(){ //freopen("in.txt","r",stdin); int n; cin>>n; init(); mem(vis,0); for(int i=1;i<=n;i++){ int k=i; for(int j=0;j<tot&&pr[j]*pr[j]<=k;j++){ if(k%pr[j]==0){ while(k%pr[j]==0){ k/=pr[j]; vis[pr[j]]+=2; } } } if(k!=1) vis[k]+=2; } LL ans=1; for(int i=0;i<=1000000;i++){ ans=ans*(vis[i]+1)%mod; } cout<<(ans+1)*qpow(2LL,mod-2)%mod<<endl; return 0;}
0 0
- 51nod 1189 阶乘分数(分解质因数)
- 51nod-阶乘分数-阶乘数质因数分解/组合计数
- 51nod 1189 阶乘分数(阶乘素因子分解)
- 【51 nod 1189】【素数+整数唯一分解定理】阶乘分数
- 51 NOD 1189 阶乘分数(素因子分解+推公式+求逆元)
- 51nod 1189 阶乘分数 (质因子分解,因子个数)
- 51 nod 1189 阶乘分数
- 51nod 1189 阶乘分数
- 【51Nod 1189】阶乘分数
- 51Nod-1189-阶乘分数
- 51nod 1189 阶乘分数
- 51nod 1189 阶乘分数
- 51nod 1189 阶乘分数 (分解质因子加上逆元,乘法逆元基本意思)
- 51Nod 1189 阶乘分数 (数论)
- [数论] 51Nod 1189 阶乘分数
- [51Nod 1189阶乘分数]数学
- 阶乘质因数分解
- [codevs2959]阶乘质因数分解
- 抢购倒计时demo
- 讲一讲CSS的position/float/display都有哪些取值
- HDOJ1013
- PPT必须懂的10种配色方法
- HDU 2612 简单bfs
- 51nod 1189 阶乘分数(分解质因数)
- MySql乱码的解决方案
- 大型网站架构系列:负载均衡详解(4)
- 在类的成员函数中调用delete this
- NO.1 This is my first article
- 浅谈yum源的配置
- poj 1065
- 利用xtrabackup工具在线建立复制环境
- Metal 着色语言编程指南 二一