Special Prime
Special Prime
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 415    Accepted Submission(s): 220
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”.
Every case has only one integer indicating L.(1<=L<=10^6)
“Special Prime” that no larger than L. If you can’t find such “Special
Prime”, just output “No Special Prime!”
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的更多相关文章
- 题解-hdu2866 Special Prime
		
Problem hdu-2866 题意:求区间\([2,L]\)有多少素数\(p\)满足\(n^3+pn^2=m^3\),其中\(n,m\)属于任意整数 Solution 原式等价于\(n^2(p+n ...
 - 【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-2886 Special Prime---数论推导
		
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2866 题目大意: 问你1到L中有多少个素数满足n^3 + p*n^2 = m^3(其中n,m为大于1 ...
 - 字符串经典的hash算法
		
1 概述 链表查找的时间效率为O(N),二分法为log2N,B+ Tree为log2N,但Hash链表查找的时间效率为O(1). 设计高效算法往往需要使用Hash链表,常数级的查找速度是任何别的算法无 ...
 - 几种经典的Hash算法的实现(源代码)
		
来源声明: http://blog.minidx.com/2008/01/27/446.html 先保存下来,以备后面研究,现在还看不懂! 哈希算法将任意长度的二进制值映射为固定长度的较小二进制值,这 ...
 - hash算法和常见的hash函数 [转]
		
Hash,就是把任意长度的输入,通过散列算法,变换成固定长度的输出,该输出就是散列值. 这种转换是一种压缩映射,也就是,散列值的空间通常远小于输入的空间,不同的输入可能 会散列成相同的输出,而不 ...
 - Java 素数 prime numbers-LeetCode 204
		
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
 - HDU 4569 Special equations(取模)
		
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
 
随机推荐
- git的使用理解(分支合并的使用理解,多人编程的解决方案)
			
本文主要记录了对git日常使用的一些理解,主要是对git分支的一些感悟. git强大的版本控制系统,之前也使用过SVN,感觉上git对于多人开发的版本控制更加强大,特别是最近对git分支的使用,更是深 ...
 - cephfs文件系统场景
			
创建cephfs文件系统: [cephfsd@ceph-admin ceph]$ cd /etc/ceph [cephfsd@ceph-admin ceph]$ ceph fs ls No files ...
 - 关于ai算法的一个点子
			
长久以来,一直想要有自己的原生算法. 今天灵感图然来了: 想到, 一个事务不但要看它本身,也要看欣赏它的人. 要研究两个方面. 你要研究音乐,也要研究欣赏音乐的人. 人之所以会欣赏音乐,而牛不可以(对 ...
 - C++ 素数对猜想
			
我的解法是先将2到n的所有素数全部列出来,再计算.将全部的素数列出来用了一个叫"埃拉托色尼筛法"的方法. 算法参照这里:https://www.sohu.com/a/2526745 ...
 - Android权限级别(protectionLevel)
			
通常情况下,对于需要付费的操作以及可能涉及到用户隐私的操作,我们都会格外敏感. 出于上述考虑以及更多的安全考虑,Android中对一些访问进行了限制,如网络访问(需付费)以及获取联系人(涉及隐私)等. ...
 - VIM多标签页
			
:tabnew 增加一个标签 :tabc 关闭当前的tab :tabo 关闭所有其他的tab :tabp 或gT 前一个 :tabn 或gt 后一个 :tabs 显示 ...
 - Linux基础命令---mysqladmin数据库管理工具
			
mysqladmin mysqladmin是mysql数据库的管理工具,可以控制.查看.修改数据库服务器的配置和状态. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedor ...
 - oracle 当月日历的sql
			
select max(sun) sun, max(mon) mon, max(tue) tue, max(wed) wed, max(thu) thu, max(fri) fri, max(sat) ...
 - oracle first_value,last_valus
			
first_value和last_value 是用来去分析函数窗口中对应列的第一个值和最后一个值的函数. 语法如下: first_value(col [ignore NULLS]) over([PAR ...
 - 监测linux系统负载与CPU、内存、硬盘、用户数的shell脚本
			
本节主要内容: 利用Shell脚本来监控Linux系统的负载.CPU.内存.硬盘.用户登录数. 一.linux系统告警邮件脚本 # vim /scripts/sys-warning.sh #!/bin ...