洛谷_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<stdio.h>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<iterator>
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#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;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值