题目描述

求不定方程 \(\frac {1}{x} + \frac{1}{y} = \frac{1}{n!}\)的正整数解的个数

\(n \leq 100^6\)

Solution

化简得

\(x * n! + y * n! = x * y\)

\(x * y - x * n! - y *n! +(n!)^2 = (n!)^2\)

\((x - n!)(y - n!) = (n!)^2\)

以上,我们可以看出,所求正整数解的个数其实就是\((n!)^2\)的约数的个数。

这个当然可以暴力求,但是很慢。考虑一个质数p在n!中出现的次数,显然是\(\frac{n}{p}\),这既表示n中包含几个p,同时也能说明小于等于n的数中,有多少个是p的倍数。同理\(p^2\)在n!中出现的次数是\(\frac{n}{p^2}\),以此类推,最后将这些全部加起来就是p在n!阶乘中出现的次数。在应用因子个数公式即可。

for(int i = 1; pri[i] <= n; ++i){
int tot = 0, x = n, y = pri[i];
while(x) tot += x / y, x /= y;
ans = (ans * (tot << 1 | 1) % mod) % mod;//之所以要<<1是因为是n!*n!
}

举个例子或许好理解。

13!中有多少个3?包含3这个因数的数有:3, 6, 9, 12,分别包含1, 1, 2, 1个3,总数就是5个。而13 / 3 = 4, 4 / 3 = 1, 4 + 1 = 5。

Code

#include <iostream>
#include <cstdio>
using namespace std;
inline long long read() {
long long x = 0; int f = 0; char c = getchar();
while (c < '0' || c > '9') f |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f? -x:x;
} const int mod = 1e9 + 7;
int n, pri[1000006], cnt;
long long ans = 1;
bool v[1000006];
inline void get_pri() {
for (int i = 2; i <= 1000000; ++i) {
if (!v[i]) pri[++cnt] = i;
for (int j = 1; j <= cnt && pri[j] * i <= n; ++j) {
v[pri[j] * i] = 1;
if (i % pri[j] == 0) break;
}
}
}
int main() {
n = read();
get_pri();
for (int i = 1; pri[i] <= n; ++i) {
int tot = 0, x = n, y = pri[i];
while (x) tot += x / y, x /= y;
ans = (ans * (tot << 1 | 1) % mod) % mod;
}
printf("%lld\n", ans);
return 0;
}

【数论】[因数个数]P4167樱花的更多相关文章

  1. 牛客练习赛25 A 因数个数和(数论分块)

    题意: q次询问,每次给一个x,问1到x的因数个数的和. 1<=q<=10 ,1<= x<=10^9 1s 思路: 对1~n中的每个数i,i作为i,2i,3i,...的约数,一 ...

  2. q次询问,每次给一个x,问1到x的因数个数的和。

    q次询问,每次给一个x,问1到x的因数个数的和. #include<cmath> #include<cstdio> #include<cstring> usingn ...

  3. 积性函数&线性筛&欧拉函数&莫比乌斯函数&因数个数&约数个数和

    只会搬运YL巨巨的博客 积性函数 定义 积性函数:对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数. 完全积性函数:对于任意整数a和b有性质f(ab)=f(a)f(b)的数论函数 ...

  4. 如何求数字n的因数个数及因数和

    我们有可能在某些数学题中会求到某个数的因数和,那我们怎么求呢? 因为我们知道任意一个合数都可以由两个或多个质数相乘得到,那么我们就先分解质因数吧 例:我们随便去一个数吧,嗯,就108了,好算... 我 ...

  5. 【牛客练习赛 25】A 因数个数和

    题目地址:https://www.nowcoder.com/acm/contest/158/A 参考博客:https://blog.csdn.net/zzcblogs/article/details/ ...

  6. LightOJ-1138 Trailing Zeroes (III) 唯一分解定理 算n!的某个因数个数

    题目链接:https://cn.vjudge.net/problem/ 题意 找一个最小的正整数n 使得n!有a个零 思路 就是有几个因数10呗 考虑到10==2*5,也就是说找n!因数5有几个 数据 ...

  7. hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...

  8. [nowcoder]因数个数和

    链接:https://www.nowcoder.com/acm/contest/158/A 考虑每个数对答案的贡献,所以答案就是$\sum_{i=1}^{n}{\lfloor\frac{n}{i}\r ...

  9. Pollard_rho定理 大数的因数个数 这个板子超级快

    https://nanti.jisuanke.com/t/A1413 AC代码 #include <cstdio> #include <cstring> #include &l ...

随机推荐

  1. python自动化使用 HtmlTestRunner 测试用例描述出现dict() -> new empty dictionary

    python自动化使用 HtmlTestRunner  测试用例描述出现dict() -> new empty dictionary这个问题,找了各种资料,发现是ddt.py 的问题 修改了dd ...

  2. SpringBoot与SpringDateJPA和Mybatis的整合

    一.SpringBoot与SpringDateJPA的整合 1-1.需求 查询数据库---->得到数据------>展示到页面上 1-2.整合步骤 1-2-1.创建SpringBoot工程 ...

  3. Python进阶----pymysql模块的使用,单表查询

    Python进阶----pymysql模块的使用,单表查询 一丶使用pymysql ​   ​   1.下载pymysql包: pip3 install pymysql ​​   ​   2.编写代码 ...

  4. asp.net 自定义特性

    今天看张子阳的.net中的反射(反射特性)一文,觉得反射配合自定义的特性确实还挺有用,之前看书.看博客之后好多心血来潮敲的代码随便往桌面上一放,时间一久,连自己也分不清它们是干嘛的了,然后就是删除,虽 ...

  5. jQuery常用方法(五)

    一.jQuery中常用方法相关方法参数说明:a.无参,获取值b.参数param,设置值c.参数function(index,oldVal){}回调函数[返回我们所要使用的新值]    回调函数的两个参 ...

  6. Redux 中间件和异步操作

    回顾一下Redux的数据流转,用户点击按钮发送了一个action,  reducer 就根据action 和以前的state 计算出了新的state, store.subscribe 方法的回调函数中 ...

  7. python 常用的标准库

    glob模块   提供了一个函数,用于匹配符合要求的文件: import glob list=glob.glob("*.py") #匹配当前目录下的所有匹配的文件名(包括后缀),以 ...

  8. tensorflow提示:No module named ''tensorflow.python.eager".

        版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_27921205/articl ...

  9. docker cannot stop container问题解决

    docker 容器在启动时出现异常,删除容器或者暂停容器时会出现cannot stop container 先使用sudo aa-remove-unknown ,再进行其他操作 lgj@lgj-Len ...

  10. redis实现消息队列-java代码实现

    转:https://blog.csdn.net/qq_42175986/article/details/88576849 pom.xml <!-- redis依赖 --> <depe ...