zoukankan      html  css  js  c++  java
  • AOJ

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34870

    求n内的素数个数。

     1 /* ***********************************************
     2 Author        : zch
     3 Created Time  :2015/5/19 8:46:16
     4 File Name     :a.cpp
     5  ************************************************ */
     6 
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <iostream>
    10 #include <algorithm>
    11 #include <vector>
    12 #include <queue>
    13 #include <set>
    14 #include <map>
    15 #include <string>
    16 #include <cmath>
    17 #include <cstdlib>
    18 #include <ctime>
    19 using namespace std;
    20 typedef long long ll;
    21 const int maxn = 1000005;
    22 int prime[maxn];
    23 bool is_prime[maxn];
    24 
    25 int solve(int n) {
    26     int p=0;
    27     for(int i=0;i<=n;i++) is_prime[i]=true;
    28     is_prime[0]=is_prime[1]=false;
    29     for(int i=2;i<=n;i++) {
    30         if(is_prime[i])
    31         {
    32             prime[p++]=i;
    33             for(int j=2*i;j<=n;j+=i)
    34                 is_prime[j]=false;
    35         }
    36     }
    37     return p;
    38 }
    39 
    40 int main()
    41 {
    42     //freopen("a.txt","r",stdin);
    43     //freopen("b.txt","w",stdout);
    44     int n;
    45     while(~scanf("%d",&n)) {
    46         printf("%d
    ",solve(n));
    47     }
    48     return 0;
    49 }

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=30390

     1 /* ***********************************************
     2 Author        : zch
     3 Created Time  :2015/5/19 9:53:16
     4 File Name     :a.cpp
     5  ************************************************ */
     6 
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <iostream>
    10 #include <algorithm>
    11 #include <vector>
    12 #include <queue>
    13 #include <set>
    14 #include <map>
    15 #include <string>
    16 #include <cmath>
    17 #include <cstdlib>
    18 #include <ctime>
    19 using namespace std;
    20 typedef long long ll;
    21 ll gcd(ll a,ll b) {
    22     return b==0?a:gcd(b,a%b);
    23 }
    24 
    25 
    26 int main()
    27 {
    28     //freopen("a.txt","r",stdin);
    29     //freopen("b.txt","w",stdout);
    30     ll x,y;
    31     while(~scanf("%lld%lld",&x,&y)) {
    32         printf("%lld %lld
    ",gcd(x,y),x/gcd(x,y)*y);
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    trailRenderer
    通过sysobjects快速查找SQLServer中是否有某个表、视图、存储过程等对象实操
    浅谈信息系统(IT)项目管理-序幕
    使用open xml 判断sharepoint文档是否损坏
    Sharepoint the file is locked for use domainuser edit.文件被锁定,解锁方式
    sharepoint 列表库指定序号规则
    Biztalk 宏
    Biztalk 在流程中定义将消息保存为文件的文件名
    Biztalk 2013 新特性简介(英)
    devexpress gridview,selectedrowchanged
  • 原文地址:https://www.cnblogs.com/nowandforever/p/4514833.html
Copyright © 2011-2022 走看看