洛谷_1445 樱花(数论)

樱花

题目链接:https://www.luogu.com.cn/problem/P1445

题解:

1 x + 1 y = 1 n ! \frac{1}{x}+\frac{1}{y}=\frac{1}{n!} x1+y1=n!1
= > x + y x y = 1 n ! => \frac{x+y}{xy}=\frac{1}{n!} =>xyx+y=n!1
= > x y = x ∗ n ! + y ∗ n ! => xy = x*n!+y*n! =>xy=xn!+yn!
= > y ( x − n ! ) = x ∗ n ! =>y(x-n!) = x*n! =>y(xn!)=xn!
= > y = x ∗ n ! x − n ! =>y = \frac{x*n!}{x-n!} =>y=xn!xn!
z = x − n ! z = x-n! z=xn!,则 x = z + n ! x = z+n! x=z+n!
= > y = n ! ∗ ( z + n ! ) z =>y = \frac{n!*(z+n!)}{z} =>y=zn!(z+n!)
= > y = n ! + n ! ∗ n ! z =>y = n!+\frac{n!*n!}{z} =>y=n!+zn!n!
x , y x,y x,y都是正整数,则 n ! ∗ n ! n!*n! n!n!需能整除z,求 n ! ∗ n ! n!*n! n!n!的因数数量即可。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define dbg(x) cout<<#x<<" = "<
#define INF 0x3f3f3f3f
#define eps 1e-6
   
using namespace std;
typedef long long LL;   
typedef pair<int, int> P;
const int maxn = 1000100;
const int mod = 1000000007;
int a[maxn];
LL getnum(int n, int x);

int main()
{
    int n, i, j, k;
    LL ans = 1;
    scanf("%d", &n);
    for(i=2;i<=n;i++)
        if(!a[i]){
            for(j=i+i;j<=n;j+=i)
                a[j] = 1;
            LL num = 2*getnum(n, i)+1;
            ans = ans*num%mod;
        }
    printf("%lld\n", ans);
    return 0;
}

LL getnum(int n, int x)
{
    LL res = 0;
    while(n){
        res += n/x;
        n /= x;
    }
    return res;
}

你可能感兴趣的:(数论)