【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 ...
随机推荐
- Floyd_Warshall算法
Floyd_Warshall算法主要用于求解所有节点对的最短路径,代码如下: #include<iostream> using namespace std; #define Inf 655 ...
- python基础--类的经典类vs新式类
经典类VS新式类区别 1)写法新式类class Person(object):#new style 经典类class Persion: #classical style 2)调用父类 新式写法用sup ...
- Vue 实现loading进度条
项目中遇到的,用vue实现下: <template> <div class="plLoading"> <div class="plLoadi ...
- NLP里面好的学习资料
别人推荐的网址: http://ruder.io/deep-learning-nlp-best-practices/index.html#wordembeddings
- 【鬼脸原创】JQuery获取元素的方法总结
目录 一.说明 二.获取本身 三.获取同级元素 四.获取父级元素 五.获取子级元素 一.说明 获取元素的方法分为两种:jQuery选择器.jQuery遍历函数. 做个总结,巩固下知识. 二.获取本 ...
- 浅谈js设计模式之单例模式
单例模式的定义是:保证一个类仅有一个实例,并提供一个访问它的全局访问点. 单例模式是一种常用的模式,有一些对象我们往往只需要一个,比如线程池.全局缓存.浏览器中的 window 对象等.在 JavaS ...
- 使用Dockerfile构建docker lnmp环境
一.mysql 1.创建 Dockerfile mkdir mysql # 创建一个目录存放之后的Dockerfile,目录名无所谓 cd mysql # 进入目录 vi Dockerfile # 创 ...
- mysql数据库主从同步复制原理
MySQL的Replication(英文为复制)是一个多MySQL数据库做主从同步的方案,特点是异步复制,广泛用在各种对MySQL有更高性能.更高可靠性要求的场合.与之对应的是另一个同步技术是MySQ ...
- 2017 MoveIt!更新 ros indigo
First MoveIt! Update in 2017. Using it on NEXTAGE pt.1 2017 MoveIt! update pt.2; Stopping motion on ...
- python2.7
python2.7支持win32.win64 下载地址:http://pan.baidu.com/s/1dE39eQ9 初学,附一个牛人的python教程地址:http://www.liaoxuefe ...