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. hadoop/spark面试题

    总结于网络 转自:https://www.cnblogs.com/jchubby/p/5449379.html 1.简答说一下hadoop的map-reduce编程模型 首先map task会从本地文 ...

  2. d3 CSS

    CSS的inline.block与inline-block 块级元素(block):独占一行,对宽高的属性值生效:如果不给宽度,块级元素就默认为浏览器的宽度,即就是100%宽. 行内元素(inline ...

  3. Linux基础命令---mirror获取ftp目录

    mirror 使用lftp登录ftp服务器之后,可以使用mirror指令从服务器获取目录   1.语法       mirror [OPTS] [source [target]]   2.选项列表 选 ...

  4. Gitlab安装操作说明书

    一.Gitlab安装操作步骤 登录官方网站https://about.gitlab.com/downloads/根据你所需要的系统版本,作者使用的是centos6, 检查您的服务器是否符合硬件要求.g ...

  5. oralce 存储过程传入 record 类型的参数?

    先定义一个 package , package中含有一个 record 类型的变量 create or replace package pkg_record is type emp_record is ...

  6. GET传参数方式

    controller:/getDetail/{id} /getDetail?id1234567 /getDetail?id=id1234567

  7. SpringBoot服务间使用自签名证书实现https双向认证

    SpringBoot服务间使用自签名证书实现https双向认证 以服务server-one和server-two之间使用RestTemplate以https调用为例 一.生成密钥 需要生成server ...

  8. 算法 A-Star(A星)寻路

    一.简介 在游戏中,有一个很常见地需求,就是要让一个角色从A点走向B点,我们期望是让角色走最少的路.嗯,大家可能会说,直线就是最短的.没错,但大多数时候,A到B中间都会出现一些角色无法穿越的东西,比如 ...

  9. <转>Java NIO API

    Java NIO API详解 NIO API 主要集中在 java.nio 和它的 subpackages 中: java.nio 定义了 Buffer 及其数据类型相关的子类.其中被 java.ni ...

  10. [BUUCTF]PWN——ez_pz_hackover_2016

    ez_pz_hackover_2016 题目附件 解题步骤: 例行检查,32位,开启了RELRO保护,二进制的保护机制看这里 由于没有开启nx保护,对于这题一开始想到的是利用写入shellcode来获 ...