Primes Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2016    Accepted Submission(s): 928
Problem Description
Given a number n, please count how many tuple(p1, p2, p3) satisfied that p1<=p2<=p3, p1,p2,p3 are primes and p1 + p2 + p3 = n.
 
Input
Multiple test cases(less than 100), for each test case, the only line indicates the positive integer
n(n≤10000).
 
Output
For each test case, print the number of ways.
 
Sample Input
3
9
 
Sample Output
0
2
 
Source

给出n,计算三个素数相加等于n的方案个数,素数打表就行
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int num[10020];
void prim()
{
for(int i=2;i<10020;i++)
{
if(num[i]==0)
{
for(int j=i+i;j<10020;j+=i)
num[j]=1;
}
}
}
int main()
{
int n;
memset(num,0,sizeof(num));
num[1]=1;
prim();
while(scanf("%d",&n)!=EOF)
{
int ans=0;
for(int i=2;i<=n;i++)
{
for(int j=i;j<=(n-i)/2;j++)
{
if(!num[i]&&!num[j]&&!num[n-i-j])
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}

 

hdoj--5104--Primes Problem(素数打表)的更多相关文章

  1. hdu 5104 Primes Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5104 Primes Problem Description Given a number n, ple ...

  2. hdu 5104 Primes Problem(prime 将三重循环化两重)

    //宁用大量的二维不用量小的三维 #include <iostream> #include<cstdio> #include<cstring> using name ...

  3. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

  4. Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力

    题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...

  5. hdu_5104 Primes Problem()

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5104 rimes Problem Time Limit: 2000/1000 MS (Java/Oth ...

  6. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  7. Aladdin and the Flying Carpet LightOJ - 1341 (素数打表 + 算术基本定理)

    题意: 就是求a的因数中大于b的有几对 解析: 先把素数打表 运用算术基本定理 求出a的所有因数的个数 然后减去小于b的因数的个数 代码如下: #include <iostream> #i ...

  8. Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)

    题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...

  9. poj 2992 Divisors (素数打表+阶乘因子求解)

    Divisors Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9617   Accepted: 2821 Descript ...

随机推荐

  1. JS高级——面向对象方式解决tab栏切换问题

    注意事项 1.给li元素注册事件,函数里面的this指的li元素,那么我们可以在注册事件之前将Tab对象用that=this进行保存 2.使用沙箱模式,所以暴露给外面的变量使用的是window.tab ...

  2. JS高级——缓存原理

    缓存的原理 1.就是将常用的数据存储起来,提供便利,减少查询次数和所消耗的事件 2.利用作用的原理所产生的数据库:非关系型数据库(内存型数据库) MongoDB.Redis等 3.还有网站静态页面缓存 ...

  3. CSS——个人资料demo

    1.上下外边距合并,选最大值. 2.两个input标签在编辑中如果换行了,在浏览器中显示的时候会自动增加一些距离. <!DOCTYPE html> <html lang=" ...

  4. Centos7搭建nginx并提供外网访问

    搭建nginx之后,80端口,其他机器无法访问 查询端口是否开启 firewall-cmd --query-port=80/tcp 永久开放80端口 firewall-cmd --permanent ...

  5. java实例1

    1.满天星星 import java.awt.*; public class xinxin { public static void main(String[] args) { Frame w = n ...

  6. python_文件io

    # -*- coding:UTF-8 -*-#从键盘读入raw_input([prompt]) #函数从标准输入读取一个行,并返回一个字符串(去掉结尾的换行符)#input([prompt]) 函数和 ...

  7. The Standard SSL Handshake

    The following is a standard SSL handshake when RSA key exchange algorithm is used: 1.  Client Hello ...

  8. On branch master nothing to commit, working tree clean ERROR: Repository not found. fatal: Could not read from remote repository.

    将gitbash部署hexo到github:hexo deploy 报以下错误: Administrator@liu MINGW64 /Hexo $ hexo d INFO Deploying: gi ...

  9. include和require区别

    1.  include()执行的时候需要引用的文件每次都要进行读取评估; require()执行时需要引用的文件只处理一次(实际上执行时需要引用的文件内容替换了require()语句) 可以看出若有包 ...

  10. 【Apache Kafka】二、Kafka安装及简单示例

    (一)Apache Kafka安装 1.安装环境与前提条件   安装环境:Ubuntu16.04   前提条件: ubuntu系统下安装好jdk 1.8以上版本,正确配置环境变量 ubuntu系统下安 ...