hdu-2886 Special Prime---数论推导
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2866
题目大意:
问你1到L中有多少个素数满足n^3 + p*n^2 = m^3(其中n,m为大于1的自然数)
解题思路:
首先简化成n^2 *( n + p ) = m^3
假设 n^2 和 n+p 之间有公共素因子 p , 那么 n+p = k*p , 即 n=p*(k-1),
带进去得到 p^3 * (k-1)^2 *k = m^3 , (k-1)^2*k 肯定是不能表示成某一个数的三次幂的,
所以假设不成立,所以 n^2 和 n+p 之间没有公共素因子 p ,
那么可以假设n=x^3 , n+p=y^3 , 相减得到 p = y^3 - x^3 = (y-x) *(y^2+y*x+x^2) , p是素数,
所以 y-x=1 (这不用过多解释了吧,素数的因子只有1和P,右括号肯定是大于1的数了)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
const int maxn = +;
int prime[maxn];
bool is_prime[maxn];
int sieve(int n)//返回n以内素数的个数
{
int p = ;
for(int i = ; i <= n; i++)is_prime[i] = ;
is_prime[] = is_prime[] = ;
for(ll i = ; i <= n; i++)
{
if(is_prime[i])
{
prime[p++] = i;
for(ll j = i * i; j <= n; j += i)is_prime[j] = ;//这里涉及i*i,必须使用long long
}
}
return p;
}
int ans[maxn];
int main()
{
sieve();
for(int i = ; ; i++)
{
int t = * i * i + * i + ;
if(t > )break;
if(is_prime[t])ans[t] = ;
}
for(int i = ; i < maxn; i++)
ans[i] += ans[i - ];
while(cin >> n)
if(ans[n])cout<<ans[n]<<endl;
else cout<<"No Special Prime!"<<endl;
return ;
}
hdu-2886 Special Prime---数论推导的更多相关文章
- 【HDU】2866:Special Prime【数论】
Special Prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 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 ...
随机推荐
- The Add-in 'VMDebugger' failed to load or caused an exception.....的解决办法
异常如图: 解决办法: (把VS的设置导出来,做出相应修改后,再导入,问题就可以解决了) 1. 在Visual Studio中选择 Tools --> Import and Export Set ...
- Laravel 使用Voyager导致多个数据库连接总是返回默认连接?
问题与分析 最近的项目碰到一个奇怪的问题,在Laravel(5.3)中想建立多个数据库连接连到MySQL的不同数据库(另一个连接名为conn2),执行如下语句得到却发现得到的仍然是默认连接: $con ...
- [转] Entity Framework添加记录时获取自增ID值
本文转自:http://blog.csdn.net/educast/article/details/8632806 与Entity Framework相伴的日子痛并快乐着.今天和大家分享一下一个快乐, ...
- Expression Blend实例中文教程(10) - 缓冲动画快速入门Easing
随着Rich Internet application(RIA)应用技术的发展,各个公司越来越注重于项目的用户体验性,在保证其功能完善,运行稳定的基础上,绚丽的UI和人性化的操作设计会给用户带来舒适的 ...
- form表单在发送到服务器时候编码方式
enctype(编码方式):规定了form表单在发送到服务器时候编码方式.有如下的三个值可选: 1.application/x-www-form-urlencoded.默认的编码方式.但是在用文本的传 ...
- javascript之Array()数组函数讲解
Array()是一个用来构建数组的内建构造器函数.数组主要由如下三种创建方式: array = new Array() array = new Array([size]) array = new Ar ...
- Effective C++ .33 子类的名称覆盖
#include <iostream> #include <cstdlib> using namespace std; class Base { public: int add ...
- crontab 切割日志
cutlog.sh #!/bin/sh source /etc/profile D=$(date "+%Y%m%d%H%M%S") mv "/usr/local/Cell ...
- 移动web开发ajax缓存操作
移动web开发过程中网速是必须考虑的一个因素,所以一般是尽可能的在本地存储数据,避免弱网环境下请求数据失败导致页面没有内容的情况. 前后端分离是web开发的必然趋势,在PC端我们有时甚至为了避免aja ...
- 原生js制作标题与内容保持4行的效果
在制作网页或移动端有时会用到一个效果,类似文章标题和文章描述的排列总是保持一样的行数,要么标题总是一行,多出的省略,要么标题内容1:3或2:2或3:1这样,今天练习这样的效果. 实现的原理:给标题和内 ...