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. Go语言之进阶篇响应报文测试方法

    1.响应报文测试方法 示例: package main import ( "fmt" "net/http" ) //服务端编写的业务逻辑处理程序 func my ...

  2. [PowerShell Utils] Remotely install Hyper-V and Failover Cluster feature on a list of windows 2012 servers

    Hello everyone, this is the second post of the series. .   Background =============== In my environm ...

  3. CentOS7安装openjdk、tomcat和mysql流程介绍

    首先是前戏,推荐一个远程工具Xshell和Xftp搭配使用,以下是Xshell的官网 http://www.netsarang.com/products/xsh_overview.html 1.ope ...

  4. Android -- Property Animation

    3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...

  5. capwap学习笔记——初识capwap(五)

    3. CAPWAP Binding for IEEE 802.11 ¢ CAPWAP协议本身并不包括任何指定的无线技术.它依靠绑定协议来扩展对特定无线技术的支持. ¢ RFC5416就是用来扩展CAP ...

  6. 转: linux进程地址图解

    http://www.cnblogs.com/clover-toeic/p/3754433.html

  7. ubuntu16.04忘了root密码

    1.开机点击ESC,进去GUN GRUB界面 2.选择有recovery mode的选项,按e进入命令行 3.找到有recovery nomodeset的行,删除recovery nomodeset, ...

  8. [Functional Programming] Introduction to State, thinking in State

    Recently, I am learning Working with ADT. Got some extra thought about State Monad. Basiclly how to ...

  9. pycharm下设置自己的模板

    在File---settings---File and Code Templates---Python script 脚本里添加: #!usr/bin/env python #-*- coding:u ...

  10. wdcp升级php5.3无法安装PDO_MySQL的解决

    重新下载php5.3的升级脚本 wget http://down.wdlinux.cn/in/php_up53.sh 不忙运行,先修改php_up53.sh,查找./configure字段,在这行的末 ...