【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 ...
随机推荐
- 【codeforces】【比赛题解】#861 CF Round #434 (Div.2)
本来是rated,现在变成unrated,你说气不气. 链接. [A]k-凑整 题意: 一个正整数\(n\)的\(k\)-凑整数是最小的正整数\(x\)使得\(x\)在十进制下末尾有\(k\)个或更多 ...
- OpenFlow1.3协议wireshark抓包分析
OpenFlow v1.0 v1.0协议消息列表如下: 分为三类消息:Controller-to-switch,asynchronous和symmertric. v1.0(包含至少一个流表,每个流表包 ...
- PHP的数据库连接mysqli遍历示例
$mysqli = mysqli_init(); $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2);//设置超时时间,以秒为单位的连接超时时间 $m ...
- GLOBAL_NAMES参数研究
最近在配置Stream时,发现必须要把GLOBAL_NAMES参数的指设置为TRUE,具体原因为何不知.但是发现在设置了该参数之后,数据库每天的物化视图刷新出现了问题.之后查明原因,是DBLINK出现 ...
- MySQL缓存命中率概述及如何提高缓存命中率
MySQL缓存命中率概述 工作原理: 查询缓存的工作原理,基本上可以概括为: 缓存SELECT操作或预处理查询(注释:5.1.17开始支持)的结果集和SQL语句: 新的SELECT语句或预处理查询语句 ...
- (一)问候 HtmlUnit
第一节: HtmlUnit 简介 htmlunit 是一款开源的java 页面分析工具,读取页面后,可以有效的使用htmlunit分析页面上的内容.项目可以模拟浏览器运行,被誉为java浏览器的开源实 ...
- ubuntu获得root用户权限,使用xshell连接!
一.获取root用户权限 打开linux终端命令,输入 sudo passwd root Enter new UNIX password: (在这输入你的密码) Retype new UNIX pas ...
- 利用Requests库写爬虫
基本Get请求: #-*- coding:utf-8 -*- import requests url = 'http://www.baidu.com' r = requests.get(url) pr ...
- Python线程和进程
一.进程 程序并不能单独和运行只有将程序装载到内存中,系统为他分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别在于:程序是指令的集合,它是进程的静态描述文本:进程是程序的一次执行活动, ...
- Linux基础入门学习笔记之三
第四节 Linux目录结构及文件基本操作 Linux目录结构 Linux 的目录与 Windows 的目录的区别 目录与存储介质(磁盘,内存,DVD 等)的关系 Windows 一直是==以存储介质为 ...