一开始提交了这个,果断TLE

 #include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
using namespace std; #define MEM(a,v) memset (a,v,sizeof(a))
// a for address, v for value #define max(x,y) ((x)>(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y)) #define debug printf("!\n") bool isPrime(int n)
{
int i;
for(i = ;i<=sqrtf(n);i++)
{
if(n%i == )
return false;
}
return true;
} int main()
{
int n;
int i,j;
int count;
while(scanf("%d",&n)!=EOF && n)
{
count = ;
for(i = ;i<=n/;i+=)
{
if(isPrime(i))
if(isPrime(n-i))
count++;
}
printf("%d\n",count);
} return ;
}

看来只能打表了

 #include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
using namespace std; #define MEM(a,v) memset (a,v,sizeof(a))
// a for address, v for value #define max(x,y) ((x)>(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y)) #define debug printf("!\n") const int MM = ; bool isPrime[MM] = {false}; void initPrime()
{
MEM(isPrime,true);
int i,j; for(i = ;i<=MM-;i++) if(i%==) isPrime[i]=false;
for(i = ;i<=MM/+;i++)
{
for(j = i+i;j<=MM-;j+=i)
isPrime[j] = false;
}
isPrime[] = false;
isPrime[] = true;
} int main()
{ int i,n;
initPrime();
while(scanf("%d",&n)!=EOF && n)
{
int count = ;
for(i = ;i<=n/;i++)
if(isPrime[i] && isPrime[n-i])
count++;
printf("%d\n",count);
} return ;
}

421MS

hdu 1397 (素数判定)的更多相关文章

  1. hdu 2012 素数判定 Miller_Rabbin

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. HDU 2012 素数判定

    http://acm.hdu.edu.cn/showproblem.php?pid=2012 Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括 ...

  3. hdu 1012 素数判定

    这道题~以前判定prime是一个个去试着整除再去存储,上次弄过欧拉函数那题目之后就知道了,这样会更快捷: prime[] = prime[] = ; ; i <maxn; i++) { if(! ...

  4. 多项式求和,素数判定 HDU2011.2012

    HDU 2011:多项式求和 Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ... 现在请你求出该多项式的前n项的和.   Input ...

  5. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  6. HDOJ2012素数判定

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  8. Codevs 1702 素数判定 2(Fermat定理)

    1702 素数判定 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 一个数,他是素数么? 设他为P满足(P< ...

  9. 素数判定 AC 杭电

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

随机推荐

  1. C#取得控制台应用程序的根目录方法

    如有雷同,不胜荣幸,若转载,请注明 取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.Curren ...

  2. 本机号码认证黑科技:极光(JG)开发者服务推出“极光认证”新产品

    近日,中国领先的大数据服务商极光(JG)推出全新产品--极光认证JVerification.极光认证是极光针对APP用户注册登陆,二次安全验证等身份验证场景打造的一款本机号码认证SDK,验证用户提供的 ...

  3. 第一站:CLion安装教程与环境配置

    原文来自:http://www.sunmey.cn/thread-129-1-1.html 本人:找了很久才找到的CLion安装教程与环境配置,这里分享给大家~ 这里要说明的一点是CLion是要钱的, ...

  4. FlowPortal-BPM——创建新模块

    一.设置webconfig (1)数据源设置 添加所有所用到数据库 (2)修改企业信息 二.Main.ashx——添加新的功能选项卡 new { id = "EXECUTE", t ...

  5. SpringCloud2.0

    一.网站架构演变过程 从传统架构(单体应用)  到   分布式架构(以项目进行拆分)  到  SOA架构(面向服务架构)  到   微服务架构 1) 传统架构: 其实就是SSH或者SSM,属于单点应用 ...

  6. Mac下包管理平台homebrew的使用

    一.安装 参考:http://www.cnblogs.com/EasonJim/p/6287098.html 二.使用 假设我要安装node,命令如下: 安装软件 brew install node ...

  7. java回调方法之理解

    以前经常看见"回调方法(或回调函数)"一词,但是没有了解过是什么意思,更不知道用法.现在从网络上搜集了一些很好的资料,自己又整理一下,作为自己的笔记,也作为学习过程中的一个小脚印. ...

  8. android开发中的BaseAdapter之理解(引用自网络,总结的很好,谢谢)

    android中的适配器(Adapter)是数据与视图(View)之间的桥梁,用于对要显示的数据进行处理,并通过绑定到组件进行数据的显示. BaseAdapter是Android应用程序中经常用到的基 ...

  9. 《LeetBook》leetcode题解(13):Roman to Integer[E]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  10. git stash使用一则

    当在新的分支工作,修改的文件提交到暂存区,这时,切换到其他分之,可能报错,因为米有commit,如果切换到其他分支,暂存区的修改可能丢失,我们可以使用git stash save -a(暂存区) &q ...