Special Prime

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 738    Accepted Submission(s):
390

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
 

Statistic | Submit | Discuss | Note

Home | Top Hangzhou
Dianzi University Online Judge 3.0
Copyright © 2005-2018 HDU ACM Team. All Rights Reserved.
Designer & Developer: Wang
Rongtao
 LinLe GaoJie GanLu
Total
0.000000(s) query 1, Server time : 2018-10-18 11:20:31, Gzip enabled
Administration

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【数论】的更多相关文章

  1. HDU2866 Special Prime

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2866 题意:在区间[2,L]内,有多少个素数p,满足方程有解. 分析: 原方程变为: n^(b-1) ...

  2. HDU 5839 Special Tetrahedron

    HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...

  3. 题解-hdu2866 Special Prime

    Problem hdu-2866 题意:求区间\([2,L]\)有多少素数\(p\)满足\(n^3+pn^2=m^3\),其中\(n,m\)属于任意整数 Solution 原式等价于\(n^2(p+n ...

  4. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  5. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

  6. 七夕节 (HDU - 1215) 【简单数论】【找因数】

    七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...

  7. Special Prime

    Special Prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. 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 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. 数据库名(DB_NAME)、实例名(Instance_name)、以及操作系统环境变量(ORACLE_SID)

    数据库名(DB_NAME).实例名(Instance_name).以及操作系统环境变量(ORACLE_SID) 在ORACLE7.8数据库中只有数据库名(db_name)和数据库实例名(instanc ...

  2. windows环境cmd下执行jar

    项目目录结构 一,在pom.xml文件里添加配置 <build> <plugins> <plugin> <groupId>org.apache.mave ...

  3. shell脚本实现分日志级别输出

    shell脚本如何优雅的记录日志信息,下面让我们一步一步,让shell脚本的日志也变得高端起来,实现如下功能 ①设定日志级别,实现可以输出不同级别的日志信息,方便调试 ②日志格式类似为:[日志级别] ...

  4. linux中core dump开启使用教程【转】

    转自:http://www.111cn.net/sys/linux/67291.htm 一.什么是coredump 我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各 ...

  5. C++中关于位域的概念

    原文来自于http://topic.csdn.net/t/20060801/11/4918904.html中的回复 位域 有些信息在存储时,并不需要占用一个完整的字节,   而只需占几个或一个二进制位 ...

  6. Visual Studio 2017 for Mac

    Visual Studio 2017 for Mac Last Update: 2017/6/16 我们非常荣幸地宣布 Visual Studio 2017 for Mac 现已推出. Visual ...

  7. mysql取以当前时间为中心的任意时间段的时间戳

    例如:取当前时间后一年的时间戳 SELECT UNIX_TIMESTAMP(date_sub(curdate(),interval -1 YEAR)) SELECT UNIX_TIMESTAMP(da ...

  8. java基础20 StringBuffer缓冲类

    1.概要 StringBuffer 其实就是一个存储字符的容器 字符串特点:字符串是常量;它们创建之后不能更改了字符串一旦发生变化,那么立马创建一个新的对象.注意:字符串的内容不适合频繁修改的,因为一 ...

  9. centos7.2安装mysql5.7

    1.安装前工作 在安装前需要确定现在这个系统有没有 mysql,如果有那么必须卸载(在 centos7 自带的是 mariaDb 数据库,所以第一步是卸载数据库). 卸载系统自带的Mariadb: 查 ...

  10. Centos中查询目录中内容命名ls

    首先解释下这块, root代表当前登录用户,localhost代表主机名, ~代表当前主机目录,  #代表用户权限   #表示超级用户,$表示普通用户: 查询目录中内容命令 ls  (list缩写) ...