zoukankan      html  css  js  c++  java
  • 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==2) return true; if(n%2==0||n==1) return false; int m=(int)(sqrt(n+1.0)); for(int i=3;i<=m;i+=2) if(n%i==0) return false; return true; } int fun(int n){ int m,i; if(n%2==0){ if(isp(n/2)) return 1; else return 0; }else{ int k; m=(int)(sqrt(n+1.0)); k=0; for(i=3;i<=m;i+=2) if(n%i==0){ if(isp(i)&&isp(n/i)) { return k=1; // printf("Yes "); break; } } if(!k) return 0; //printf("No "); } } int main() { int n; int m; int i,k; while(scanf("%d",&n)!=EOF){ if(fun(n)) printf("Yes "); else printf("No "); } return 0; }

    // 郁闷 求出所有素数 还是不如上述快

    #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/3],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==2) return true; if(n%2==0||n==1) return false; int m=(int)(sqrt(n+1.0)); for(int i=3;i<=m;i+=2) if(n%i==0) return false; return true; } int getprime(){ int i,j; f[1]=true; for(i=4;i<=maxn;i+=2) f[i]=true; int m=(int)(sqrt(maxn+1.0)); for(i=3;i<=m;i+=2){ for(j=i*i;j<=maxn;j+=i) f[j]=true; } for(i=1;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=0; while(prim[i]<=m){ if(n%prim[i]==0&&!f[n/prim[i]]) { k=1; break; } i++; } if(!k) printf("No "); else printf("Yes "); } return 0; }
    
    
    
    
    
  • 相关阅读:
    Linux shell read命令
    mysql 详解 01
    centos 6/7 mysql 5.7 修改root密码 mysql root密码找回
    iptables基本原理讲解与规则的增删改查
    nginx反向代理https访问502, nginx反向代理, 支持SNI的https回源,SNI源点,nginx反向代理报错
    nginx 配置 强制访问https
    有名管道FIFO进程间数据传输实例
    命名管道FIFO及其读写规则
    224、Basic Calculator
    (匿名)管道的读写规则
  • 原文地址:https://www.cnblogs.com/372465774y/p/3208798.html
Copyright © 2011-2022 走看看