Title Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1189
Topic Ideas:
1/n! = 1/x +1/y
==> n! * (x + y) = x * Y (right-pass, then conversion)
==> n!^2 = (x-n!) * (y-n!) (add n side to both sides)
==> A = b * C, a = n!^2, B = x-n! , C = y-n!
#include <iostream>#include <cstring>#include <cstdio>using namespace STD;typedef Long LongLL;Const intMoD =1e9+7;Const intmaxn=1e6+5;BOOLPRIME[MAXN];intp[maxn/Ten];intKvoidIsPrime () {k=0; LL i,j;memset(Prime,true,sizeof(prime)); for(i=2; i<maxn; i++) {if(Prime[i]) {p[k++]=i; for(j=i*i; j<maxn; j+=i) prime[j]=false; } }/*for (int i=0; i<10; i++) cout<<p[i]<< ""; */}ll get (ll M, ll p) {if(m<p)return 0;returnM/p+get (m/p,p);} ll Quickmod (ll A, ll b) {ll ans =1; while(b) {if(b&1) Ans=ans*a%mod; b>>=1; A=a*a%mod; }returnAns;}intMain () {isprime ();intN while(~scanf("%d", &n)) {LL ans=1; LL m = Quickmod (2, (LL) mod-2); for(intI=0; i<k&&p[i]<=n; i++) {LL tmp = (get (n,p[i)) *2+1)%mod; Ans=ans*tmp%mod; } ans = ans*m%mod; Ans = (ans+m%mod)%mod;printf("%lld\n", ans); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The nod 1189 factorial fraction