题目大意:这道题中给了一种数的定义,让求在某个区间内的这种数的个数。这种数的定义是:有且只有一个素因子的合数。

题目分析:这种数的实质是素数的至少两次幂。由此打表——打出最大区间里的所有这种数构成的表即可。

代码如下:

 # include<iostream>
# include<cstdio>
# include<cmath>
# include<set>
# include<cstring>
# include<algorithm>
using namespace std;
const long long N=;
# define ll long long
int pri[],mark[];
set<ll>s;
ll mypow(int a,int b)
{
if(b==)
return a;
ll u=mypow(a,b/);
u*=u;
if(b&)
u*=a;
return u;
}
void init()
{
pri[]=;
memset(mark,,sizeof(mark));
for(int i=;i<=;++i){
if(!mark[i])
pri[++pri[]]=i;
for(int j=;j<=pri[]&&i*pri[j]<=;++j){
mark[i*pri[j]]=;
if(i%pri[j]==)
break;
}
}
for(int i=;i<=pri[];++i){
ll u=(pri[i]+0LL)*(pri[i]+0LL);///在这要对pri[i]进行强制类型转换,否则溢出。
while(u<N){
s.insert(u);
u=u*pri[i];
}
}
}
void work(ll a,ll b)
{
int ans=;
set<ll>::iterator it1,it2;
it1=lower_bound(s.begin(),s.end(),a);
it2=lower_bound(s.begin(),s.end(),b);
while(it1!=it2){
++it1;
++ans;
}
printf("%d\n",ans);
}
int main()
{
init();
int T;
ll l,r;
scanf("%d\n",&T);
while(T--)
{
scanf("%lld%lld",&l,&r);
work(l,r);
}
return ;
}

对于这一类问题:一定要理解透彻题中的新定义,否则费了半天劲写出来的东西是错的,既浪费时间,又浪费精力。

UVA-10539 Almost Prime Numbers的更多相关文章

  1. UVA 10539 - Almost Prime Numbers(数论)

    UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...

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

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

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

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

  4. POJ 2739. Sum of Consecutive Prime Numbers

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

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

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

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

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

  8. Codeforces 385C Bear and Prime Numbers

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

  9. POJ2739 Sum of Consecutive Prime Numbers(尺取法)

    POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...

  10. Alexandra and Prime Numbers(思维)

    Alexandra and Prime Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

随机推荐

  1. jQuery 是javascript的一个库(常用插件、处理器)

    jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery就是javascript的一个库,把我 ...

  2. Oracle查询session连接数和inactive以及 概要文件IDLE_TIME限制用户最大空闲连接时间

    -----############oracle会话和进程################----------------查询会话总数select count(*) from v$session;--查 ...

  3. IDEA上传代码到码云

  4. P1771 方程的解_NOI导刊2010提高(01)

    P1771 方程的解_NOI导刊2010提高(01) 按题意用快速幂把$g(x)$求出来 发现这不就是个组合数入门题吗! $k$个人分$g(x)$个苹果,每人最少分$1$个,有几种方法? 根据插板法, ...

  5. P3868 [TJOI2009]猜数字

    [TJOI2009]猜数字 中国剩余定理 求解i=1 to n : x≡a[i] (mod b[i])的同余方程组 设 t= ∏i=1 to n b[i] 我们先求出 i=1 to n : x≡1 ( ...

  6. Linux 环境 HTTP 服务器

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <netinet/in ...

  7. 20145332 《网络攻防》 逆向与Bof实验

    20145332 <网络攻防>逆向与Bof实验 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用 ...

  8. java使用itex读取pdf,并搜索关键字,为其盖章

    导读:近期要做一个根据关键字定位pdf的盖章位置的相关需求,其中关键字可配置多个(包含pdf文档中可能不存在的关键字),当页面显示盖章完成时,打开pdf显示已经损坏. 排查后发现,当itext搜索的关 ...

  9. linux下去掉pdf的密码(前提:知道密码)

    一.背景 Linux jello 4.16.3 SMP Thu Apr 19 07:32:02 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux 二.去掉密码 2.1 先 ...

  10. Msys2的安装,并整合到cmder中

    下载:msys2-x86_64-20161025.exe 下载安装包,然后装上. 打开msys的shell之后首先升级一下pacman,然后就可以愉快地Syu了. $ pacman -Sy pacma ...