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. Android基础TOP4_1:点击物理按钮弹出退出提示框

    JAVA: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedIns ...

  2. spring编程框架

    spring boot, spring data, spring framework spring / spring boot @Profile('prod'|'dev'|'other')(伴随@Be ...

  3. 图论 Make Unique:有向图和无向图的一些算法

    计算机科学入门资料之一的<算法与数据结构-C语言版>,覆盖了基础算法的几乎所有分支,其中的一个典型分支为图理论. 一个简介:图论基础-图数据结构基础 一个简洁的博客:图论基础,简列一本书 ...

  4. (转) Arcgis4js实现链家找房的效果

    http://blog.csdn.net/gisshixisheng/article/details/71009901 概述 买房的各位亲们不知是否留意过链家的"地图找房",这样的 ...

  5. Forum/viewthread.php代码备份

    <!--{eval $lzthread = DB::fetch_all("SELECT `tid`,`subject` FROM ".DB::table('forum_thr ...

  6. IOS7升级攻略

    1) Select the main view, set the background color to black (or whatever color you want the status ba ...

  7. HDU-4055 Number String 动态规划 巧妙的转移

    题目链接:https://cn.vjudge.net/problem/HDU-4055 题意 给一个序列相邻元素各个上升下降情况('I'上升'D'下降'?'随便),问有几种满足的排列. 例:ID 答: ...

  8. Going Home HDU - 1533(最大费用最小流)

    On a grid map there are n little men and n houses. In each unit time, every little man can move one ...

  9. 弹层蒙版(mask),ios滚动穿透,我们项目的解决方案

    问题描述 项目开发遇到一个ios独有的问题,在wkwebview中稳定复现 问题: 弹出一个蒙版,当在蒙版上面滑动的时候蒙版后面的内容滚动了 这当然是ios的bug,但是经过我们测试iphone7也会 ...

  10. 【POJ 1860】Currency Exchange

    [题目链接]:http://poj.org/problem?id=1860 [题意] 给你n种货币,m种货币之间的交换信息; 交换信息以 A,B,RA,CA,RB,CB的形式给出; 即A换B的话假设A ...