AOJ - 0009 Prime Number (素数筛法) && AOJ - 0005 (求最大公约数和最小公倍数)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34870
求n内的素数个数。
/* ***********************************************
Author : zch
Created Time :2015/5/19 8:46:16
File Name :a.cpp
************************************************ */ #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
const int maxn = ;
int prime[maxn];
bool is_prime[maxn]; int solve(int n) {
int p=;
for(int i=;i<=n;i++) is_prime[i]=true;
is_prime[]=is_prime[]=false;
for(int i=;i<=n;i++) {
if(is_prime[i])
{
prime[p++]=i;
for(int j=*i;j<=n;j+=i)
is_prime[j]=false;
}
}
return p;
} int main()
{
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
while(~scanf("%d",&n)) {
printf("%d\n",solve(n));
}
return ;
}
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=30390
/* ***********************************************
Author : zch
Created Time :2015/5/19 9:53:16
File Name :a.cpp
************************************************ */ #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) {
return b==?a:gcd(b,a%b);
} int main()
{
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
ll x,y;
while(~scanf("%lld%lld",&x,&y)) {
printf("%lld %lld\n",gcd(x,y),x/gcd(x,y)*y);
}
return ;
}
AOJ - 0009 Prime Number (素数筛法) && AOJ - 0005 (求最大公约数和最小公倍数)的更多相关文章
- AOJ 0009 Prime Number
题意:给出n,求不大于n的素数有多少个. 算法:先用线性时间复杂度的筛法打素数表,对于每个输入统计不超过的素数个数. #include <cstdio> int p[100010]; bo ...
- JD 题目1040:Prime Number (筛法求素数)
OJ题目:click here~~ 题目分析:输出第k个素数 贴这么简单的题目,目的不清纯 用筛法求素数的基本思想是:把从1開始的.某一范围内的正整数从小到大顺序排列, 1不是素数,首先把它筛掉.剩下 ...
- 【Aizu - ALDS1_1_C】Prime Numbers(素数筛法)
Prime Numbers Descriptions: A prime number is a natural number which has exactly two distinct natur ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 素数筛法--SPOJ Problem 2 Prime Generator
质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单, ...
- 题目1040:Prime Number(第k个素数)
题目链接:http://ac.jobdu.com/problem.php?pid=1040 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- hdu-2136 Largest prime factor---巧用素数筛法
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2136 题目大意: 每个素数在素数表中都有一个序号,设1的序号为0,则2的序号为1,3的序号为2,5的 ...
- ZOJ 1842 Prime Distance(素数筛选法2次使用)
Prime Distance Time Limit: 2 Seconds Memory Limit: 65536 KB The branch of mathematics called nu ...
- Prime Path素数筛与BFS动态规划
埃拉托斯特尼筛法(sieve of Eratosthenes ) 是古希腊数学家埃拉托斯特尼发明的计算素数的方法.对于求解不大于n的所有素数,我们先找出sqrt(n)内的所有素数p1到pk,其中k = ...
随机推荐
- 802.11 wireless 1(主要还是学习ccna wireless的体系)
802.11 wireless 1(主要还是学习ccna wireless的体系)ISM频带(ISM band starts early 1990s)900MHZ 2.4GHZ 5GHZ 四种 ...
- 【CentOS】安装chrome
参考资料:http://www.cnblogs.com/xia520pi/p/3545715.html 问题描述: 出现如下错误: 升级glibc任然无效,最后在博客园:http://www.cnbl ...
- OpenSSL心脏出血漏洞全回顾
近日网络安全界谈论的影响安全最大的问题就是Heartbleed漏洞,该漏洞是4月7号国外黑客曝光的.据Vox网站介绍,来自Codenomicon和谷歌安全部门的研究人员,发现OpenSSL的源代码中存 ...
- win7/8下VirtualBox虚拟Ubuntu共享文件夹设置
实验环境: 主机:win8.1 虚拟机软件:VirtualBox4.3 虚拟的主机:centos6.5 final 亲测可用! 1. 安装增强功能包(VBoxGuestAdditions) 打开虚拟 ...
- Appstore提交 被拒绝
Reasons 16.1: Apps that present excessively objectionable or crude content will be rejected 16.1 We ...
- LA 4727
Integers 1, 2, 3,..., n are placed on a circle in the increasing order as in the following figure. W ...
- SGU 104
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB PROBLEM Yo ...
- 动态调用wcf接口服务
1.url:http://localhost:8002/名称.svc/basic(.svc结尾) 2.需要引用的命名空间System.ServiceModel 3.调用代码: public class ...
- [你必须知道的.NET]第三十三回,深入.NET 4.0之,Lazy<T>点滴
发布日期:2009.10.29 作者:Anytao © 2009 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 对象的创建方式,始终代表了软件工业的生产力方向,代表了先进软件技 ...
- poj 2975 Nim 博弈论
令ans=a1^a2^...^an,如果需要构造出异或值为0的数, 而且由于只能操作一堆石子,所以对于某堆石子ai,现在对于ans^ai,就是除了ai以外其他的石子 的异或值,如果ans^ai< ...