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 = ...
随机推荐
- openwrt的交叉编译
默认情况下,openwrt编译脚本会自动从Internet上获取所需要的软件包源代码,并把下载的源码包存放在当前目录的 dl/ 目录中: 在 build_dir/ 目录中存放编译中使用的软件包, ...
- 科学技术法转成BigDemcial
目的:将类似“-412615050624334534247E-3”转成“-412615050624334534.247” 工具:用到BigDemcial Code: public static voi ...
- 2016ACM-ICPC Qingdao Online青岛网络赛题解
TonyFang+Sps+我=5/12 滚了个大粗 2016年9月21日16:42:36 10题完工辣 01 题意:求形同的数中大于n的最小值 题解:预处理所有的(5194个),在这里面二分 #inc ...
- Leetcode#147 Insertion Sort List
原题地址 心得:有关链表的题目,多用中间变量,代码写得清晰一点,适当注释 代码: ListNode *insertionSortList(ListNode *head) { if (!head) re ...
- Search API 官方文档 可以用了查看自己的app
Search API October 24, 2012 - HTTPS is now supported for Search and Lookup requests. Please update y ...
- 在线最优化求解(Online Optimization)之五:FTRL
在线最优化求解(Online Optimization)之五:FTRL 在上一篇博文中中我们从原理上定性比较了L1-FOBOS和L1-RDA在稀疏性上的表现.有实验证明,L1-FOBOS这一类基于梯度 ...
- Sencha Touch 2.4 callParent() 用法
callParent() 用法 方法介绍 用来调用父类的同名方法,并传参,这在从一个框架类派生且要重写诸如onRender这样的方法时会经常看到. 传参方式 1.arguments Ext.defin ...
- JQuery表单验证插件EasyValidator,超级简单易用!
本插件的宗旨是:用户无需写一行JS验证代码,只需在要验证的表单中加入相应的验证属性即可,让验证功能易维护,可扩展,更容易上手. DEMO中已经包含了常用的正则表达式,可以直接复用,为了考虑扩展性,所以 ...
- linux 上传/下载文件到windows工具
一般来说,linux服务器大多是通过ssh客户端来进行远程的登陆和管理的,使用ssh登陆linux主机以后,如何能够快速的和本地机器进行文件的交互呢,也就是上传和下载文件到服务器和本地: 与ssh ...
- 【☆】javascript数据类型拾遗
一.Array对象 1.两个数组能用< > == ===做比较吗? 答:数组可以用> <进行矩阵比较,比如a=[1,2,3] b=[1,2,4],那么a<b,如果a的数值 ...