zoj 2723 Semi-Prime
// 题意都不好理解 我以为是求 一个数被分成2个素数和 然后是求分成2个素数积
// 坑爹 忘记写 !=EOF 然后一直超时 然后换了几种 还是超时 一看别人代码 速度明显比我慢
// 然后发现被自己坑了 #include <iostream>
#include <math.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
#define maxm 10010
#define maxn 1000010
int gcd(int a,int b){
int r;
while(r=a%b){a=b;b=r;}
return b;
}
bool isp(int n){
if(n==) return true;
if(n%==||n==) return false;
int m=(int)(sqrt(n+1.0));
for(int i=;i<=m;i+=)
if(n%i==) return false;
return true;
}
int fun(int n){
int m,i;
if(n%==){
if(isp(n/))
return ;
else
return ;
}else{
int k;
m=(int)(sqrt(n+1.0));
k=;
for(i=;i<=m;i+=)
if(n%i==){
if(isp(i)&&isp(n/i))
{
return k=;
// printf("Yes\n");
break;
}
}
if(!k) return ; //printf("No\n");
}
}
int main()
{
int n;
int m;
int i,k; while(scanf("%d",&n)!=EOF){
if(fun(n)) printf("Yes\n");
else printf("No\n");
} return ;
}
// 郁闷 求出所有素数 还是不如上述快 #include <iostream>
#include <math.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
#define maxm 10010
#define maxn 1000010
int prim[maxn/],p;
bool f[maxn];
int gcd(int a,int b){
int r;
while(r=a%b){a=b;b=r;}
return b;
}
bool isp(int n){
if(n==) return true;
if(n%==||n==) return false;
int m=(int)(sqrt(n+1.0));
for(int i=;i<=m;i+=)
if(n%i==) return false;
return true;
}
int getprime(){
int i,j;
f[]=true;
for(i=;i<=maxn;i+=)
f[i]=true;
int m=(int)(sqrt(maxn+1.0));
for(i=;i<=m;i+=){
for(j=i*i;j<=maxn;j+=i)
f[j]=true;
}
for(i=;i<=maxn;i++)
if(!f[i]) prim[p++]=i;
}
int main()
{
int n;
int m;
int i,k;
getprime();
while(scanf("%d",&n)!=EOF){
m=(int)(sqrt(n+1.0));
k=i=;
while(prim[i]<=m){
if(n%prim[i]==&&!f[n/prim[i]])
{
k=;
break;
}
i++;
}
if(!k) printf("No\n"); else printf("Yes\n");
} return ;
}
zoj 2723 Semi-Prime的更多相关文章
- ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!
两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...
- zoj 2723 Semi-Prime(素筛打表+搜索优化)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2723 题目描述: Prime Number Definitio ...
- ZOJ 3707 Calculate Prime S 数论
思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...
- zoj 2723 Semi-Prime(set)
Semi-Prime Time Limit: 2 Seconds Memory Limit: 65536 KB Prime Number Definition An integer grea ...
- ZOJ - 3483 - Gaussian Prime
先上题目: Gaussian Prime Time Limit: 3 Seconds Memory Limit: 65536 KB In number theory, a Gaussian ...
- G - G ZOJ - 2723 (素数打表+set)
Prime Number Definition An integer greater than one is called a prime number if its only positive di ...
- ZOJ 1457 Prime Ring Problem(dfs+剪枝)
Prime Ring Problem Time Limit: 10 Seconds Memory Limit: 32768 KB A ring is compose of n circ ...
- POJ 1595 Prime Cuts (ZOJ 1312) 素数打表
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...
- Prime Query (ZOJ 3911 线段树)
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a sequen ...
随机推荐
- windows 下c++编译
http://blog.csdn.net/dyllove98/article/details/9314993
- 客户端服务端通信protocol
这个协议不知我在上面耗费了多长时间,也有人问过我咋回事,这个protocol不长,但对于我来说理解起来很费劲,今天回来看看忽然看懂了(80%),只能说不知看了多少遍 其实这些东西应该在来的一个月这样子 ...
- 任务调度 QUARTZ
任务调度在目前的JAVA应用程序中运用的十分普遍,故掌握QUARTZ是必备的技能 闲话少说,上官网:http://www.quartz-scheduler.org/ 下载最新1.80资源包 commo ...
- httpclient 人人网
登录的站点是3g.renren.com 因为是手机人人, 页面比较简单 首先用HttpGet取出"http://3g.renren.com"的html代码, 是用Jsoup解析出登 ...
- 自定义nagios check_load告警阀值
自定义nagios check_load告警阀值 日期:2012-01-11 来源: heipark 分享至: - 默认check_load配置 define service{ use generi ...
- mac os 下如何清除/切换svn eclipse插件的用户
以mac os x为例(Unix/Linux类似), 1.打开命令行窗口,即用户的根目录(用户的home目录) $ ls -al ... drwxr-xr-x 6 linxyz staff ...
- ORA-04052\ ORA-00604\ORA-12154
ORA-04052: error occurred when looking up remote object TBCS.SUBS_PRIVILEGE@DD2A ORA-00604: error oc ...
- Hibernate逍遥游记-第5章映射一对多-01单向<many-to-one>、cascade="save-update"、lazy、TransientObjectException
1. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...
- 电容值E系列标称方法
本节首先介绍常用的E系列标称方法,然后介绍电阻.电容器.电感器.二极管的分类.性能和识别方法,以及简单的实用电路. 一.E系列标称方法 厂家生产的电阻器,并不是包含任何阻值,就像人民币,只有1.2.5 ...
- ScannerDemo------string int
import java.util.Scanner; /** *Scanner演示 */ public cl ...