Special Prime

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

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
思路:假设 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 肯定是不能表示成某一个数的三次幂的,所以假设不成立,gcd(K,K+1)=1,假设n=x^3 , n+p=y^3 , 相减得到 p = y^3 - x^3 = (y-x) *(y^2+y*x+x^2)p是素数,y-x=1 , p =(x+1)^3 - x^3 = 3*x^2+3*x+1,然后枚举x,判断求得数是否是素数即可;
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<queue>
5 #include<set>
6 #include<math.h>
7 #include<string.h>
8 using namespace std;
9 typedef long long LL;
10 bool prime[1000005];
11 int sum[1000005];
12 int main(void)
13 {
14 int i,j;
15 memset(sum,0,sizeof(sum));
16 for(i = 2; i <=1000; i++)
17 {
18 if(!prime[i])
19 {
20 for(j = i; (i*j) <= 1000000; j++)
21 {
22 prime[i*j] = true;
23 }
24 }
25 }
26 for(i = 0;; i++)
27 {
28 int x = 3*i*i+3*i+1;
29 if(x > 1e6)
30 break;
31 if(!prime[x])
32 {
33 sum[x] = 1;
34 }
35 }sum[1] = 0;
36 for(i = 1; i <= 1e6; i++)
37 {
38 sum[i] += sum[i-1];
39 }
40 int n;
41 while(scanf("%d",&n)!=EOF)
42 { if(sum[n])
43 printf("%d\n",sum[n]);
44 else printf("No Special Prime!\n");
45 }
46 return 0;
47 }
 

Special Prime的更多相关文章

  1. 题解-hdu2866 Special Prime

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

  2. 【HDU】2866:Special Prime【数论】

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

  3. HDU2866 Special Prime

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

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

  5. 字符串经典的hash算法

    1 概述 链表查找的时间效率为O(N),二分法为log2N,B+ Tree为log2N,但Hash链表查找的时间效率为O(1). 设计高效算法往往需要使用Hash链表,常数级的查找速度是任何别的算法无 ...

  6. 几种经典的Hash算法的实现(源代码)

    来源声明: http://blog.minidx.com/2008/01/27/446.html 先保存下来,以备后面研究,现在还看不懂! 哈希算法将任意长度的二进制值映射为固定长度的较小二进制值,这 ...

  7. hash算法和常见的hash函数 [转]

       Hash,就是把任意长度的输入,通过散列算法,变换成固定长度的输出,该输出就是散列值. 这种转换是一种压缩映射,也就是,散列值的空间通常远小于输入的空间,不同的输入可能 会散列成相同的输出,而不 ...

  8. Java 素数 prime numbers-LeetCode 204

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  9. HDU 4569 Special equations(取模)

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

随机推荐

  1. ProxyApi-大数据采集用的IP代理池

    用于大数据采集用的代理池 在数据采集的过程中,最需要的就是一直变化的代理ip. 自建adsl为问题是只有一个区域的IP. 买的代理存在的问题是不稳定,影响采集效率. 云vps不允许安装花生壳等,即使有 ...

  2. ChromeDriver的安装和使用

    用于驱动Chrome浏览器,适用于有界面的操作系统. 一.安装ChromeDriver 要先安装Chrome浏览器,然后安装ChromeDriver. 官方网站:https://sites.googl ...

  3. Typora数学公式输入指导手册

    Markdown 公式指导手册 公式大全的链接 https://www.zybuluo.com/codeep/note/163962#mjx-eqn-eqsample 目录 Markdown 公式指导 ...

  4. Hive(四)【DML 数据导入导出】

    目录 一.数据导入 1.1 [load]--向数据中装载数据 案例 1.2 [insert]--查询语句向表中插入数据 案例 1.3 [as select]--查询语句中创建表且加载数据 案例 1.4 ...

  5. 零基础学习java------day1------计算机基础以及java的一些简单了解

    一. java的简单了解 Java是一门面向对象编程语言,不仅吸收了C++的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征.Java语言作为静态 ...

  6. 【TCP/IP】之Java socket编程API基础

    Socket是Java网络编程的基础,深入学习socket对于了解tcp/ip网络通信协议很有帮助, 此文讲解Socket的基础编程.Socket用法:①.主要用在进程间,网络间通信. 文章目录如下: ...

  7. 08-认证(Authorization)

    这又是一个非常实用的功能,对我们做接口测试来说,经常要处理登录认证的情况 .如果不用这个Authorization其实也能解决认证的问题,无非就是把要认证的数据按照要求在指定位置传入参数即可.比如我们 ...

  8. ORACLE 获取执行计划的方法

    一.获取执行计划的6种方法(详细步骤已经在每个例子的开头注释部分说明了): 1. explain plan for获取: 2. set autotrace on : 3. statistics_lev ...

  9. this指针的用法和基本分析

    当在不同的对象中采用this指针,就已经是在给它赋值了.对象各自的this指针指向各自对象的首地址,所以不同对象的this指针一定指向不同的内存地址. this 指针是由系统自动提供的指向对象的特殊指 ...

  10. 网页设计单位 px,em,rem,vm,vh,%

    px(pixels) 像素 (px) 是一种绝对单位,因为无论其他相关的设置怎么变化,像素指定的值是不会变化的. px就是设备或者图片最小的一个点,比如常常听到的电脑像素是1024x768的,表示的是 ...