hdu1397(素数组和成偶数的个数 用 标记法)
This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of all the pairs of prime numbers satisfying the condition in the conjecture for a given even number.
A sequence of even numbers is given as input. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are interested in the number of essentially different pairs and therefore you should not count (p1, p2) and (p2, p1) separately as two different pairs.
10
12
0
2
1
#include<iostream>
#include<cmath>
using namespace std;
int prime[800000];
int isprime(int a)//判断是否是素数
{
int i;
for (i=2;i<=sqrt(a*1.0)+0.5;i++)
if(a%i==0)
return 0;
return 1;
}
void prime_b()//打素数表
{
int i;
for(i=2;i<=32768;i++)
if(isprime(i))//i是素数记为1
prime[i]=1;
else //不是记为0
prime[i]=0;
}
int main()
{
int n,p,k; prime_b(); while(cin>>n&&n)
{
k=0;
if(prime[n-2])//和2组和的数
k++;
for(p=3;p<=n/2;p+=2)
if(prime[p]&&prime[n-p])
k++;
cout<<k<<endl;
}
}
hdu1397(素数组和成偶数的个数 用 标记法)的更多相关文章
- c语言实践 统计输入的一串正整数里面奇数和偶数的个数
怎么考虑这个问题. 首先先确定肯定是需要一个变量保存输入的数据的,我们叫它input,最后结果要的是个数,所以需要另外两个变量来保存奇数的个数和偶数的个数. int input int countJ ...
- 代码实现:判断101-200之间有多少个素数(质数),并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。
package com.loaderman.Coding; /* 判断101-200之间有多少个素数(质数),并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能 ...
- hdu 2098 分拆素数和(一个偶数拆分成两个不同素数和 拆法数量)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2098 分拆素数和 Time Limit: 1000/1000 MS (Java/Others) ...
- LightOJ1336 Sigma Function(约数和为偶数的个数)
Sigma Function Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- 洛谷 P1865 A % B Problem[筛素数/前缀和思想/区间质数个数]
题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对于每次询问输出个数 t,如l或r∉[1,m]输出 Cros ...
- 剑指offer21----数组中奇数偶数
题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分. 基本实现 如果不考虑时间复杂度,最简单的思路应该是从头扫描这个数组,每 ...
- 66.Subarray Sum Equals K(子数组和为K的个数)
Level: Medium 题目描述: Given an array of integers and an integer k, you need to find the total number ...
- :判断101-200之间有多少个素数,并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。
package C; public class Sushu { public static void main(String[] args) { int sum=0; for (int i = 101 ...
- Java--数组转成list,list转数组
数组转成list: 方法一: String[] userid = {"aa","bb","cc"}; List<String> ...
随机推荐
- JAVA GUI学习 - JSplitPane分屏组件学习
public class JSplitPaneKnow extends JFrame { JSplitPane jSplitPane; JPanel jPanelRed; JPanel jPanelB ...
- Android 全屏方法
我大概不想赘述什么其他方法,我就说一下我已知在用的方法QAQ requestWindowFeature(Window.FEATURE_NO_TITLE); 设置程序无标题栏 getWindow().s ...
- pomelo
简介 Pomelo 是基于 Node.js 的高性能.分布式游戏服务器框架.它包括基础的开发框架和相关的扩展组件(库和工具包),可以帮助你省去游戏开发枯燥中的重复劳动和底层逻辑的开发.Pomelo 不 ...
- 详解iOS开发之自定义View
iOS开发之自定义View是本文要将介绍的内容,iOS SDK中的View是UIView,我们可以很方便的自定义一个View.创建一个 Window-based Application程序,在其中添加 ...
- css两列布局,一边固定宽度,另一边自适应
<!DOCTYPE HTML><HTML> <head> <meta charset="utf-8" ...
- Nlog的简单使用
Nlog是.net平台下的开源日志组件,相当于log4net用法配置更简单.用途可以将日志输出到数据库,文本文件,控制台等.首先引用NLog.dll,顺便也将NLog.xml丢到运行目录准备工作完后, ...
- Setting property 'source' to 'org.eclipse.jst.jee.server [问题点数:40分]
链接地址:http://bbs.csdn.net/topics/390131469 警告: [SetContextPropertiesRule]{Context} Setting property ' ...
- django1.6.x(python3.3)使用pymysql连接mysql
1.安装 pymysql,地址:https://code.google.com/p/pymysql/ 2.安装django 然后执行 django-admin.py startproject mysi ...
- Java Web学习笔记(1)
1.项目名称用小写,类名用大小写骆驼式,对象名用骆驼式但是第一个字母是小写: 2.写对象属性时要空行,第一个方法也要空行,一般要加注释: 3.new 新的对象时等号左右要空格,if语句左右摇有空格: ...
- HBase性能测试
hbase org.apache.hadoop.hbase.PerformanceEvaluationUsage: java org.apache.hadoop.hbase.PerformanceEv ...