HDU 2866-Special Prime(数论)
来源:互联网 发布:办公软件图标 编辑:程序博客网 时间:2024/06/18 05:09
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2866
题意:问你1到L中有多少个素数满足n^3 + p*n^2 = m^3(其中n,m为大于1的自然数)
题目思路:直接暴力n和m肯定是不现实的,呢就要从这个式子下手了,化简一下得到 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的数了),
故 p =(x+1)^3 - x^3 = 3*x^2+3*x+1 , 暴力一下x,判断是否是素数就ok了。。。
#include<map> #include<stack> #include<queue> #include<vector> #include<math.h> #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; typedef long long ll; #define inf 1000000000 #define mod 1000000007 #define maxn 5000500#define lowbit(x) (x&-x) #define eps 1e-10 int a[maxn]={1,1};int main(void){ll i,j,n,k=0,num;for(i=2;i<=maxn;i++){if(a[i])continue;for(j=i*i;j<=maxn;j+=i)a[j]=1;}while(scanf("%lld",&n)!=EOF){num=0;for(i=1;;i++){ll tmp=3*i*i+3*i+1;if(tmp>n)break;if(a[tmp]==0)num++;}if(num>0)printf("%lld\n",num);elseprintf("No Special Prime!\n");}return 0;}
阅读全文
0 0
- HDU 2866-Special Prime(数论)
- hdu 2866 Special Prime(数论,推公式)
- hdu 2866 Special Prime
- HDU 2866 Special Prime 找规律
- Special Prime HDU
- HDU 2964 Prime Bases(数论)
- HDU 2136 Largest prime factor(数论)
- HDU 2964 Prime Bases 数论
- hdu 2964 Prime Bases 数论~~
- HDU 3792——Twin Prime Conjecture(数论)
- hdu 2136 Largest prime factor(数论:打表)
- POJ 1595 && HDU 1319 Prime Cuts(数论)
- HDU 4135 Co-prime(容斥原理 + 基础数论)
- HDU 2136 Largest prime factor 数论-素数
- csu 1756 prime(数论)
- FZU1797 Special Prime
- HDU2866 Special Prime
- hdu(3395)Special Fish
- Java泛型原理详解
- Poi2010 Monotonicity 2
- C++Buffer缓冲区-Gh0st远程控制源码摘取
- 1572 Self-Assembly
- title
- HDU 2866-Special Prime(数论)
- 接口的定义
- codeforces-827C-树状数组,同余定理
- 《大话数据解构》第一、二章
- Linux
- Codeforces 832D-Misha, Grisha and Underground(LCA)
- TensorFlow 学习笔记-入门篇
- 【HDU 6047】Maximum Sequence(DP)
- B 树详解