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(数论)的更多相关文章

  1. UVA 10539 - Almost Prime Numbers 素数打表

    Almost prime numbers are the non-prime numbers which are divisible by only a single prime number.In ...

  2. UVA - 10539 Almost Prime Numbers (几乎是素数)

    题意:输入两个正整数L.U(L<=U<1012),统计区间[L,U]的整数中有多少个数满足:它本身不是素数,但只有一个素因子. 分析: 1.满足条件的数是素数的倍数. 2.枚举所有的素数, ...

  3. UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

      Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people e ...

  4. UVA 1415 - Gauss Prime(数论,高斯素数拓展)

    UVA 1415 - Gauss Prime 题目链接 题意:给定a + bi,推断是否是高斯素数,i = sqrt(-2). 思路:普通的高斯素数i = sqrt(-1),推断方法为: 1.假设a或 ...

  5. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  6. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  7. 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 ...

  8. 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 ...

  9. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

随机推荐

  1. QT - 内存泄漏检测

    一.安装vld-2.5.1-setup.exe 下载地址:https://archive.codeplex.com/?p=vld 二.pro中添加头文件目录与库目录 INCLUDEPATH += &q ...

  2. pthread_create 报函数参数不匹配问题

    pthread_create方法遇到类方法时总会报  argument of type ‘void* (Thread::)(void*)’ does not match ‘void* (*)(void ...

  3. UML图与软件开发过程那点关系

    首先,软工文档, 软工文档,也就是计划,设计,描述,使用软件的一些文件,它最大的特点就是固定不变,用来给不同的人和计算机来阅读.在期间,文档起到了桥梁的作用,看这张图很形象: 在这里在看一下国家统一规 ...

  4. Lucene学习——IKAnalyzer中文分词

    一.环境 1.平台:MyEclipse8.5/JDK1.5 2.开源框架:Lucene3.6.1/IKAnalyzer2012 3.目的:测试IKAnalyzer的分词效果 二.开发调试 1.下载框架 ...

  5. Linux下安装nmap扫描工具

    NMAP是一款流行的网络扫描和嗅探工具,被广泛应用在黑客领域做漏洞探测以及安全扫描,更多的nmap是一个好用的网络工具,在生产和开发中也经常用到,主要做端口开放性检测和局域网信息的查看收集等,不同Li ...

  6. Java复习2-对象与类

    回顾基础知识过程中遇到的感觉需要记录一下的知识点. 封装 我们设计的class应当尽可能的高内聚,体现为封装的程度.一个class的属性应该只能自己修改,其他class都只是与本class沟通,而不应 ...

  7. unity3d Player Settings 中的Stripping Level(剥离等级)对应每个等级具体剥离了哪些库

    http://docs.unity3d.com/410/Documentation/ScriptReference/MonoCompatibility.html

  8. SQL Server 多条查询结果组合

    假如存在下面这张表users: 1.通过sql语句返回总人数.男生总数和女生总数 select count(1) '总人数', (select count(1) from users u2 where ...

  9. 一个小栗子聊聊JAVA泛型基础

    背景 周五本该是愉快的,可是今天花了一个早上查问题,为什么要花一个早上?我把原因总结为两点: 日志信息严重丢失,茫茫代码毫无头绪. 对泛型的认识不够,导致代码出现了BUG. 第一个原因可以通过以后编码 ...

  10. Dubbo-Fail to decode request due to: RpcInvocation

    使用Dubbo进行服务化,遇到如下错误: Caused by: com.alibaba.dubbo.remoting.RemotingException: Fail to decode request ...