ACW1294 樱花【约数个数+欧拉筛+逆向思维】

Date:2021.12.29

题意:给定一个整数 n,求有多少正整数数对 (x,y) 满足 1 x \frac{1}{x} x1 + 1 y \frac{1}{y} y1 = 1 n ! \frac{1}{n!} n!1,答案对 1 0 9 10^9 109+7 取模。
1≤ n ≤ 1 0 6 10^6 106

思路:推公式如下图。前置知识:阶乘分解
在这里插入图片描述

代码如下:

//由公式 等价于求(n!)^2的约数个数
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int N = 1e6+10,mod=1e9+7;
LL n;
LL cnt,prime[N];
bool st[N];
map<LL,LL>q;
void init()
{
    for(int i=2;i<=n;i++)
    {
        if(!st[i]) prime[cnt++]=i;
        for(int j=0;prime[j]<=n/i;j++)
        {
            st[prime[j]*i]=true;
            if(i%prime[j]==0) break;
        }
    }
}
int main()
{
    cin>>n;
    init();
    for(int i=0;i<cnt;i++)
    {
        LL res=0,p=prime[i],t=n;
        while(t)
        {
            res+=t/p;
            t/=p;
        }
        q[prime[i]]+=res;
    }
    LL sum=1;
    for(int i=0;i<cnt;i++)
        sum=sum*(2*q[prime[i]]%mod+1)%mod;
    cout<<sum;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值