[原创]“玲珑杯”ACM 比赛 Round #9 A -- Check-in Problem [因子个数]【数论】
2017-02-10 21:31:20 Tabris_ 阅读数:440
博客爬取于 2020-06-14 22:41:42
以下为正文
版权声明:本文为 Tabris 原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/54974236
题目连接:http://www.ifrog.cc/acm/problem/1084
----------------------------------------------------------------------------------------------------------.
A -- Check-in Problem
Time Limit:5s Memory Limit:128MByte
Submissions:921 Solved:55
DESCRIPTION
A positive integer x is called p-bizarre number if the number of the divisors of x is p exactly.
Your task is testing whether the given positive integer n is a p-bizarre number or not.
INPUT
The first line contains a positive integer T, which represents there are T test cases.
The following is test cases. For each test case:
The only one line contains a positive integer n and an odd prime p.
1≤T≤10^5,1≤n≤10^18,2< p≤10^9
OUTPUT
For each test case, output in one line, print "YES" (without quote) if n is a p-bizarre number, print "NO" (without quote) otherwise.
SAMPLE INPUT
3
9 3
971528476274196481 7
150094635296999121 37
SAMPLE OUTPUT
YES
NO
YES
----------------------------------------------------------------------------------------------------------.
题目大意:
就是问你 n 的因子个数是不是 p 个
解题思路:
对于一个素数 n 的因子个数 我们可以对 n 做算术基本定理展开
n = p_1^{a_1}\times p_2^{a_2}\times p_3^{a_3}\times ...\times p_r^{a_r}
那么数的因子个数就是 \sum_{i = 1}^{r}(a_1+1)\times (a_2+1)\times (a_3+1)\times ...\times (a_n+1)
input 里面又说
The only one line contains a positive integer n and an odd prime p.
那么对于 p 是素数的情况 只能说明 n 的质因子只有一种,
因为上述,所以我想到以对 1e6(因为题目说 p 最小是 3,n 最大是 10^18,所以 1e6 就够了)内的素数筛法取一遍,然后二分寻找答案即可注意会爆 LL ,但是无论怎么控制溢出,最后代码写成了这样但是还是 WA...心塞...
献上官方题解
注意到p 是质数,只有当 n 是质数的 p−1 次幂时, n 的约数才可能恰好有 p 个,所以判定一个正整数 n 是 p-奇异数,只需检验 ^{p-1}\sqrt {n} 是整数,且 ^{p-1}\sqrt {n} 是质数。预处理 \sqrt {10^9} 以内的素数(共 $3401 个),进行开根和判断素数即可,时间复杂度 O\left(\dfrac {\sqrt n}{ \ln n}\right) 。 事实上 p>3 的情况很少有解,直接预处理所有有解的情况即可,可以防止写出有问题的开根,而 p=3 的判断素数也可以用 Miller-Rabin 算法判定(需要 O(1)$ 的模乘法)。
改了 2 个小时的溢出,最后都没签到。。。。。。
献上标程一枚
----------------------------------------------------------------------------------------------------------.
1 | # include <cmath> |


