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 ...
随机推荐
- C# 中请求数据方式
#region 根据URL获取结果集 /// <summary> /// 根据URL获取结果集 默认为GET,如果数据量大了可以传入POST // ...
- 精华阅读第 9 期 |滴滴出行 iOS 客户端架构演进之路
「架构都是演变出来的,没有最好的架构,只有最合适的架构!」最近,滴滴出行平台产品中心 iOS 技术负责人李贤辉接受了 infoQ 的采访,阐述了滴滴的 iOS 客户端架构模式与演变过程.李贤辉也是移动 ...
- 2015年最新中国知网CNKI免费账号直接入口
以下是Free9免费资源网小编收集整理的2015年最新中国知网CNKI免费账号直接入口,现免费分享给大家(仅供测试使用),此类文献数据库资源有时效性,希望对您的学习.工作上有所帮助! 中国知网直接入口 ...
- 0到N数其中三个数的全排列
#include<iostream> using namespace std; int main(){ ; int count; count=; ;i<=N;i++) ;j<= ...
- SQLMap使用
http://www.freebuf.com/articles/web/29942.html http://sqlmap.org/ http://blog.csdn.net/zgyulongfei/a ...
- POJ2586Y2K Accounting Bug
http://poj.org/problem?id=2586 Description Accounting for Computer Machinists (ACM) has sufferred fr ...
- IText 生成页脚页码
做doc文档报表的时候可能遇到这样的需求: 每一个页面需要页码,用IText可以完成这样的需求. IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.ja ...
- php相关学习资源
相关书籍资源: 1:PHP和MySQL Web开发 经典书籍 视频教程: PHP开发工程师闯关记--初识PHP php调试技巧: PHP 程序员的调试技术 使用 print 语句.错误报告和 PHPE ...
- asp.net中当服务器出错时显示指定的错误页面
http://blog.csdn.net/helloxiaoyu/article/details/2943537 此篇文章描述了当异常再ASP.NET中发生时怎样使用C#.NET代码去拦截和相应异常. ...
- Ios 弹框 MJPopup,KxMenu
IOS 弹框 如果直接弹出一个自定义的视图 可以选用第三方: MJPopup 弹出: if(!bandview) { bandview=[[[NSBundle mainBundle]loadNibNa ...