【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 ...
随机推荐
- Hibernate5笔记9--Hibernate注解式开发
Hibernate注解式开发: (1)注解式开发的注意点: Hibernate中使用注解,主要是为了替代映射文件,完成“类到表,属性到字段”的映射. JPA提供了一套功能强大的注解.Hibernat ...
- Floyd_Warshall算法
Floyd_Warshall算法主要用于求解所有节点对的最短路径,代码如下: #include<iostream> using namespace std; #define Inf 655 ...
- HTTP与HTTPS相关知识
URL的开头一般会有http或https,这是访问资源需要的协议类型.有时还会看到ftp.sftp.smb开头的URL,这些都是协议类型.一般使用得最多的还是http和https. HTTP HTTP ...
- nginx 的多域名多https转发设置方法【转】
version: 1.1(fixed) 修正一些错误基本环境:/etc/nginx/nginx.conf #保持/etc/nginx/ssl/ #ssl认证文件/etc/nginx/site-a ...
- C# 日文网址转punnycode
Uri uri = new Uri(url); IdnMapping idn = new IdnMapping();url= url.Replace(uri.Host, idn.GetAscii(ur ...
- ifdef等宏的妙用
条件编译 一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一部分内容指定编译的条件,这就是"条件编译". 条件编译命令最常见 ...
- windows 下的一些常用命令提示符
windows下dos命令窗口输入 netstat -ano即可查看端口使用情况, 如果要查看指定端口是否被占用 使用命令netstat -ano|findstr 端口号, 例如要查看8080端口号是 ...
- HDU 2819 Swap(行列式性质+最大匹配)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2819 题目大意:给你一个n*n的01矩阵,问是否可以通过任意交换整行或者整列使得正对角线上都是1. ...
- MySQL学习笔记:delete
使用 SQL 的 DELETE FROM 命令来删除 MySQL 数据表中的记录. 语法: DELETE FROM table_name [WHERE Clause] 如果没有指定 WHERE 子句, ...
- Rewrite HTTP to HTTPS in Nginx
1.推荐配置 server { listen 80; server_name example1.com example2.com; return 301 https://$host$request_u ...