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. [leetcode]Rotate Image @ Python

    原题地址:https://oj.leetcode.com/problems/rotate-image/ 题意: You are given an n x n 2D matrix representin ...

  2. 读书笔记,《Java 8实战》,第四章,引入流

       集合是Java中使用最多的API,但集合操作却远远算不上完美.主要表现在两点,    第一,集合不能让我们像数据库的SQL语言一样用申明式的语言指定操作:    第二,现在的集合API无法让我们 ...

  3. 【Javascript设计模式1】-单例模式

    <parctical common lisp>的作者曾说,如果你需要一种模式,那一定是哪里出了问题.他所说的问题是指因为语言的天生缺陷,不得不去寻求和总结一种通用的解决方案. 不管是弱类型 ...

  4. (转)C# SendMessage 参数与例子

    原文:http://hi.baidu.com/ytmeng/blog/item/25f5de5157931a888c543001.html using System;using System.IO;u ...

  5. 解决使用Properties读取中文乱码问题

    web服务返回的是多行以key和value对应的键值对,且编码为utf-8.我的项目使用的编码也是utf-8,但是我用Properties读取中文的时候,打印出来的总是乱码. 后来网上查了一下,得到如 ...

  6. 使用Java开发微信公众平台(二)——消息的接收与响应

    上一篇文章(http://www.jerehedu.com/fenxiang/171807_for_detail.htm )中,我们学习了使用Java语言开发微信公众平台的第一部分——环境搭建与开发接 ...

  7. Idea 自动导入包的*设置99

    作者:Intopass 链接:https://www.zhihu.com/question/35806024/answer/64530300 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权, ...

  8. KVM 虚拟化技术

    1.1 前言 1.1.1 什么是虚拟化? 在计算机技术中,虚拟化(技术)或虚拟技术(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源(CPU.内存.磁盘空间.网络适配器 ...

  9. 提高Mxd地图渲染出图效率的方法

    测试 在ArcGIS地图渲染非常耗时,特别是标注较多时,下面是做的一些性能测试   小结 1.地图渲染的数据量是显示出图速度的关键.主要注意: (1)与数据库存储的数据量关系不大.例如数据库有1万条数 ...

  10. springboot项目中报错:listener does not currently know of SID given in connect descriptor

    springboot项目中报错:listener does not currently know of SID given in connect descriptor 出现这个问题的原因是SID写错了 ...