UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers
题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅仅能整除一个素数。
思路:既然是仅仅能整除一个素数,那么这些数肯定为素数的x次方(x > 1),那么仅仅要先打出素数表,然后在素数表上暴力找一遍就能够了,由于素数表仅仅要找到sqrt(Max),大概100W,然后每一个数找的复杂度为log(n),这样复杂度是能够接受的。
代码:
#include <stdio.h>
#include <string.h> const int N = 1000005;
int t, vis[N], pn = 0;
long long l, r, prime[N]; int main() {
for (int i = 2; i < N; i++) {
if (vis[i]) continue;
prime[pn++] = i;
for (int j = i; j < N; j += i)
vis[j] = 1;
}
scanf("%d", &t);
while (t--) {
scanf("%lld%lld", &l, &r);
long long ans = 0;
for (int i = 0; i < pn; i++) {
for (long long j = prime[i] * prime[i]; j <= r; j *= prime[i]) {
if (j >= l) ans++;
}
}
printf("%lld\n", ans);
}
return 0;
}
UVA 10539 - Almost Prime Numbers(数论)的更多相关文章
- UVA 10539 - Almost Prime Numbers 素数打表
Almost prime numbers are the non-prime numbers which are divisible by only a single prime number.In ...
- UVA - 10539 Almost Prime Numbers (几乎是素数)
题意:输入两个正整数L.U(L<=U<1012),统计区间[L,U]的整数中有多少个数满足:它本身不是素数,但只有一个素因子. 分析: 1.满足条件的数是素数的倍数. 2.枚举所有的素数, ...
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ...
- UVA 1415 - Gauss Prime(数论,高斯素数拓展)
UVA 1415 - Gauss Prime 题目链接 题意:给定a + bi,推断是否是高斯素数,i = sqrt(-2). 思路:普通的高斯素数i = sqrt(-1),推断方法为: 1.假设a或 ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )
Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...
- HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)
Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...
- Codeforces 385C Bear and Prime Numbers
题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...
随机推荐
- 从零开始学C++之模板(三):缺省模板参数(借助标准模板容器实现Stack模板)、成员模板、关键字typename
一.缺省模板参数 回顾前面的文章,都是自己管理stack的内存,无论是链栈还是数组栈,能否借助标准模板容器管理呢?答案是肯定的,只需要多传一个模板参数即可,而且模板参数还可以是缺省的,如下: temp ...
- iOS截屏方法
//获取屏幕截屏方法 - (UIImage *)capture { // 创建一个context UIGraphicsBeginImageContextWithOptions(self.view.bo ...
- Java Math.sqrt()方法
描述 java.lang.Math.sqrt(double a) 返回正确舍入的一个double值的正平方根.特殊情况: 如果参数是NaN或小于为零,那么结果是NaN. 如果参数是正无穷大,那么结果为 ...
- python2.7 调用 .net的webservice asmx
首先安装pip install suds 或下载:https://pypi.org/project/suds-jurko/0.6/#files 这个是最新版本 由于不支持python3.6, 所以只能 ...
- Android -- DiskLruCache
DiskLruCache 创建一个磁盘缓存对象: public static DiskLruCache open(File directory, int appVersion, int valueCo ...
- eclipse help说明链接
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Freference%2Fcdt_u_prop_bu ...
- Eclipse小技巧:收起outline的头文件
- 10.2.1itools导入不了歌曲
首先下载iTools 4抢先版,下载地址:http://update2.itools.hk/api/v1/redirect?p=itools4&c=pc_Thinksky 点击电脑桌面左下方“ ...
- Android 为何比 iOS 卡?【转载】
Android 卡是必须的,当你的手机装了 20 多个 app,那不卡才叫见鬼了呢,我手机微信都打不开,手机直接自动重启啦~哪种东西生来就是完美的呢?即便是台式机,也是越用越慢.换句话,如果没有特别原 ...
- Jenkins 集成Unity3D Xcode
如果Mac 上没有安装brew.先安装:ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)& ...