51nod1189 阶乘分数

(x-n!)(y-n!)=n!2 ans=t[n]+1.t表示的是n!2的小于n!的约数个数。
n!2=p1a1*p2a2*p3a3...t[n]=(a1+1)*(a2+1)...-1 /2;
2对于n!的贡献为[n/2]+[n/4]+[n/8]...依次类推。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
const int nmax=1e6+5;
const int mod=1e9+7;
const int tt=5e8+4;
bool vis[nmax];int pe[nmax<<3],sm[nmax<<3];
int main(){
	int n;scanf("%d",&n);
	int cnt=0,tp;
	rep(i,2,n) {
		if(!vis[i]) pe[++cnt]=i;
		rep(j,1,cnt){
			tp=pe[j];if((ll)i*tp>n) break;vis[i*tp]=1;
			if(i%tp==0) break;
		}
	}
	ll u;
	rep(i,1,cnt){
		u=pe[i];
		while(u<=n) sm[i]+=n/u,u*=pe[i];
	}
	ll ans=1;rep(i,1,cnt) ans=ans*(sm[i]*2+1)%mod;
	printf("%lld
",(ans+1)*tt%mod);
	return 0;
}

1189 阶乘分数

题目来源: Spoj
基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
 收藏
 关注
1/N! = 1/X + 1/Y(0<x<=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
原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5868368.html