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> ...
随机推荐
- AOP 面向切面编程、拦截器
AOP(Aspect-Oriented Programming,面向切面的编程),它是可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术.它是一种新的方法论, ...
- Special Subsequence(离散化线段树+dp)
Special Subsequence Time Limit: 5 Seconds Memory Limit: 32768 KB There a sequence S with n inte ...
- HDU 1796 容斥原理 How many integers can you find
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理 纪念一下 TMD看了好久才明白DFS... 先贴代码后解释 #includ ...
- Android 建造者(Builder)模式
关于 Builder 模式 详述:http://blog.csdn.net/jjwwmlp456/article/details/39890699 先来张图 看到 Android 中 使用了 Bui ...
- CSS3线性渐变linear-gradient
转自 http://www.w3cplus.com/content/css3-gradient CSS3的线性渐变 一.线性渐变在Mozilla下的应用 -moz-linear-gradient( [ ...
- Decorator Pattern(装饰模式)
装饰模式:动态的给一个对象添加一些额外的职责.当然我们也可以通过继承来实现类似的功能,但是随着子类的增多,各种子类的组合会造成子类的急剧膨胀. Requirement: 假设客户有一个要求,需要打一个 ...
- Java thread中对异常的处理策略
转载:http://shmilyaw-hotmail-com.iteye.com/blog/1881302 前言 想讨论这个话题有一段时间了.记得几年前的时候去面试,有人就问过我一个类似的问题.就是j ...
- leetcode208 happynumber
19 is a happy number 12 + 92 = 82 82 + 22 = 68 62 + 82 = 100 12 + 02 + 02 = 1 class Solution {public ...
- [C#参考]事件和委托的关系
前面说了委托,接下来就要说一说事件了,同时最后再说一下委托和事件的区别. 事件和委托很相似,事件就好像是被简化的针对特殊用途的委托.看下面的图: 从这张图中能看到,事件是发布者的一个成员,它不是类型. ...
- {% load staticfiles %}
原先写法 {# <link rel="stylesheet" href="/static/css/reset.css"/>#} 不使用路径写法,方便 ...