【HDU】2866:Special Prime【数论】
Special PrimeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description
Give you a prime number p, if you could find some
natural number (0 is not inclusive) n and m, satisfy the following expression: We call this p a “Special Prime”. AekdyCoin want you to tell him the number of the “Special Prime” that no larger than L. For example: If L =20 1^3 + 7*1^2 = 2^3 8^3 + 19*8^2 = 12^3 That is to say the prime number 7, 19 are two “Special Primes”. Input
The input consists of several test cases.
Every case has only one integer indicating L.(1<=L<=10^6) Output
For each case, you should output a single line indicate
the number of “Special Prime” that no larger than L. If you can’t find such “Special Prime”, just output “No Special Prime!” Sample Input
7
777 Sample Output
1
10 Hint
Source
Recommend
gaojie
|
|||
|
Solution
纯数论推式子找性质辣
分析:$n^b + p*n^{b-1} = m^b ==> n^{b-1}*[n+p]=m^b$
因为$n$里面要么有$p$因子,要么没有,所以$gcd(n^{b-1},n+p)=1$或(含有p因子的数)
当$gcd(n^{b-1},n+p)== (含有p因子的数)$的时候,显然无解,因为假设有解,那么$n=K*p , K^{b-1}*p^b*(K+1)$
如果希望上面的$==m^b$,那么$K^{b-1} *(K+1)$必须能表示成某个数X的b次方,而$gcd(K,K+1)=1$,所以他们根本就没共同因
子,所以没办法表示成$X$的$b$次方,所以$gcd(n^{b-1},n+p)=1$
假设$n=x^b$,$n+p=y^b$,那么显然$m=x^{b-1}*y$,而$p=y^b-x^b$
显然$(y-x)|p$,那么必须有$y-x=1$,所以$y=x+1$,代上去就发现,$p=(x+1)^b-x ^b$。所以枚举$x$,然后判断$p$是否是素数即可。
---------------------
作者:acdreamers
来源:CSDN
原文:https://blog.csdn.net/acdreamers/article/details/8572959
Code
#include<bits/stdc++.h>
using namespace std; int isnot[], prime[], t, ans[]; void init() {
isnot[] = ;
for(int i = ; i <= ; i ++) {
if(!isnot[i]) prime[++t] = i;
for(int j = ; j <= t; j ++) {
int v = prime[j] * i;
if(v > ) break;
isnot[v] = ;
if(i % prime[j] == ) break;
}
}
for(int i = ; ; i ++) {
int v = (i + ) * (i + ) * (i + ) - i * i * i;
if(v > ) break;
if(!isnot[v]) {
ans[v] = ;
}
}
for(int i = ; i <= ; i ++) ans[i] += ans[i - ];
} int main() {
int n;
init();
while(scanf("%d", &n) == ) {
if(n < ) printf("No Special Prime!\n");
else printf("%d\n", ans[n]);
}
return ;
}
【HDU】2866:Special Prime【数论】的更多相关文章
- HDU2866 Special Prime
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2866 题意:在区间[2,L]内,有多少个素数p,满足方程有解. 分析: 原方程变为: n^(b-1) ...
- HDU 5839 Special Tetrahedron
HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...
- 题解-hdu2866 Special Prime
Problem hdu-2866 题意:求区间\([2,L]\)有多少素数\(p\)满足\(n^3+pn^2=m^3\),其中\(n,m\)属于任意整数 Solution 原式等价于\(n^2(p+n ...
- HDU 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- 七夕节 (HDU - 1215) 【简单数论】【找因数】
七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...
- Special Prime
Special Prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- SpringCloud常用注解
一 @EnableDiscoveryClient,@EnableEurekaClient的区别 SpringCLoud中的“Discovery Service”有多种实现,比如:eureka, con ...
- python基础--shutil模块
shutil模块提供了大量的文件的高级操作. 特别针对文件拷贝和删除,主要功能为目录和文件操作以及压缩操作.对单个文件的操作也可参见os模块. 注意 即便是更高级别的文件复制函数(shutil.cop ...
- CNN Architectures(AlexNet,VGG,GoogleNet,ResNet,DenseNet)
AlexNet (2012) The network had a very similar architecture as LeNet by Yann LeCun et al but was deep ...
- Java HashCode详解
一.为什么要有Hash算法 Java中的集合有两类,一类是List,一类是Set.List内的元素是有序的,元素可以重复.Set元素无序,但元素不可重复.要想保证元素不重复,两个元素是否重复应该依据什 ...
- snmp常见操作
常用snmp OID说明下面这些值可以手动连接进行获取数据: 用zabbix监控交换机和路由器需要一款能够获取网络设备OID的工具,可用getif来获得OID 也可以使用snmpwalk 配置交换机的 ...
- mongodb导入导出
导出 mongoexport -d 数据库 -c 表名 -o 输出文件名 例:mongoexport -d Mongodb_DataManager -c Kujiale_Users -o Kujial ...
- 程序设计实习MOOC / 程序设计与算法(三)第一周测验
作业题: 7. 填空(2分)简单的swap 通过码是 ( 请参考公告中的“关于编程作业的说明”完成编程作业(请注意,编程题都要求提交通过码,在openjudge上提交了程序并且通过以后,就可以下载到通 ...
- USACO 5.5 Hidden Password
Hidden Password ACM South Eastern Europe -- 2003 Sometimes the programmers have very strange ways of ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...
- xmanager
[root@upright91 run]# ./runBenchmark.sh updbtpcc.properties sqlTableCreates Exception in thread &quo ...