hdu 1397 (素数判定)
一开始提交了这个,果断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 (素数判定)的更多相关文章
- hdu 2012 素数判定 Miller_Rabbin
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 2012 素数判定
http://acm.hdu.edu.cn/showproblem.php?pid=2012 Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括 ...
- hdu 1012 素数判定
这道题~以前判定prime是一个个去试着整除再去存储,上次弄过欧拉函数那题目之后就知道了,这样会更快捷: prime[] = prime[] = ; ; i <maxn; i++) { if(! ...
- 多项式求和,素数判定 HDU2011.2012
HDU 2011:多项式求和 Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ... 现在请你求出该多项式的前n项的和. Input ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDOJ2012素数判定
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- algorithm@ 大素数判定和大整数质因数分解
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...
- Codevs 1702 素数判定 2(Fermat定理)
1702 素数判定 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 一个数,他是素数么? 设他为P满足(P< ...
- 素数判定 AC 杭电
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
随机推荐
- css 做幻灯片效果
设置一个div 盒子 <div class="ani"></div> 设置css 样式 .ani{ width:480px; height:320px; ...
- 【Qt】Qt在Windows下的开发与调试环境配置
前文已经交待了从源码编译Qt自定义版本.现在可以开始配置一下开发与调试程序并写个Hello World了. 1. IDE 虽然Qt官方有VS插件使我们可以在VisualStudio中开发Qt应用,但我 ...
- 总结day7 ---- 文件操作,读,写,追加,以及相关方法
内容大纲 一:文件的基本操作, >常见问题 >encoding >绝对路径和相对路径的 二:文件的读写追加相关操作 >读(r, r+ ,rb,r+b) >写(w,w+,w ...
- linux互传文件nc命令
使用nc命令可以很快的在两台主机传递文件,且不需要在同一网段,只要设置好端口即可. 一.安装(CentOS下) yum install -y nc (需要root权限,可以用加上sudo) 二.使用 ...
- ReactNative常用组件库 react-native-camera 相机
通过react-native-camera调用原生相机,及自定义样式 GitHub地址: https://github.com/react-native-community/react-native- ...
- 'qt_sql_default_connection' is still in use
出现这个告警是因为打开了多个db而没有及时关闭,网上搜了答案是使用完了执行 QSqlDatabase::removeDatabase(m_connectionName); 泄漏的问题有所改善,但点快了 ...
- 安装CentOS 7.4时服务器出现No Caching mode page found问题的解决方法
2019-03-27 前提准备条件: 操作系统:centos 7.4:服务器使用U盘安装,U盘使用UltraISO制作启动盘 安装过程出现的问题: [sdb] No Caching mode page ...
- 什么是WCF(转)
什么是WCF(Windows Communication Foundation(WCF)) 大家可以百度一下了解什么是WCF.当然有些人看到密密麻麻的黑框白字就懒的读.即使读了 可能也没明白确切的含义 ...
- (转)生活中的OO智慧——大话面向对象五大原则
一·单一职责原则(Single-Responsibility Principle) 定义:一个对象应该只包含单一的职责,并且该职责被完整地封装在一个类中. 宿舍里并不能好好学习,自习还是得去图书馆.这 ...
- Js 中的false,零值,null,undefined和空字符串对象
转自 http://www.imkevinyang.com/2009/07/javascript-中的false零值nullundefined和空字符串对象.html 在Javascript中,我们 ...