题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5104

rimes Problem

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

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
 
题意:输入一个数字n,找出三个数字p1,p2,p3,满足p1<=p2<=p3并且p1+p2+p3=n
 //筛素数
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
bool pri[N];
int prime[N];
int cnt;
void init()
{
cnt = ;
pri[] = pri[] = ;
for(int i = ; i < N; i++)
{
if(!pri[i]){
prime[cnt++] = i;
for(int j = i+i; j < N; j+=i)
{
pri[j] = ;
}
}
}
return;
}
int main()
{
int n;
init();
while(~scanf("%d",&n))
{
int ans = ; //printf("%d\n",cnt);
for(int i = ; i < cnt; i++)
{
if(*prime[i]>n) break;
for(int j = i; j < cnt; j++)
{
if(prime[i]+*prime[j]>n) break;
//for(int k = j; k < cnt; k++)
//{
// if(prime[i]+prime[j]+prime[k]==n) ans++;// printf("%d %d %d\n",prime[i],prime[j],prime[k]);printf("%d %d %d\n",i,j,k);}
// }
if(!pri[n-prime[i]-prime[j]]) ans++;
}
}
printf("%d\n",ans);
}
return ;
}

hdu_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. Project Euler Problem 10

    Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...

  4. hdoj--5104--Primes Problem(素数打表)

    Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. hdu 5104(数学)

    Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)

    Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. (Problem 47)Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2  7 15 = 3  5 The fi ...

  8. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  9. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

随机推荐

  1. 【WebGL】《WebGL编程指南》读书笔记——第4章

    一.前言        今天继续第四章的学习内容,开始学习复合变换的知识. 二.正文        Example1: 复合变换 在书中,作者为我们封装了一套用于变换的矩阵对象:Matrix4对象.它 ...

  2. 线上平滑升级nginx1.12

    .下载相关包,需要和之前用到的依赖包保持一致 wget http://nginx.org/download/nginx-1.12.2.tar.gz wget https://bitbucket.org ...

  3. eclipse 更换 JDK 版本后报错

    在实际开发过程中,可能由于项目的需要,我们需要更换 JDK 的版本.但是更换后会报错,如下: Java compiler level does not match the version of the ...

  4. JSP EL隐含对象

    JSP 内置对象 JSP EL隐含对象 描述 page pageScope page 作用域 request requestScope request 作用域 session sessionScope ...

  5. SVG 入门——理解viewport,viewbox,preserveAspectRatio

    工欲善其事必先利其器,没有真正搞懂SVG里的viewport,viewbox, preserveAspectRatio这三个属性,就很容易遇到坑,最近写项目用到svg这三个属性被我一眼就略过 ,后来发 ...

  6. Python函数返回不定数量的值

    Python的函数是可以return多个值的,但其本质上还是返回单个值,只是利用了tuple的自动打包,将多个值打包成单个tuple返回. 使用代码验证: def func_a(): return 1 ...

  7. exports与module.exports,export与export default 之间的关系和区别

    首先我们要明白一个前提,CommonJS模块规范和ES6模块规范完全是两种不同的概念. CommonJS模块规范 Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个 ...

  8. 机器学习小记——KNN(K近邻) ^_^ (一)

    为了让绝大多数人都可以看懂,所以我就用简单的话语来讲解机器学习每一个算法 第一次写ML的博文,所以可能会有些地方出错,欢迎各位大佬提出意见或错误 祝大家开心进步每一天- 博文代码全部为python 简 ...

  9. 我的Python学习笔记(三):私有变量

    一.私有变量的定义 在Python中,有以下几种方式来定义变量: xx:公有变量 _xx:单前置下划线,私有化属性或方法,类对象和子类可以访问,from somemodule import *禁止导入 ...

  10. Python File flush方法应用

    # flush()使用# #!/usr/bin/python# # -*- coding: UTF-8 -*-## # 打开文件# fo = open("runoob.txt", ...