UVA-10539 Almost Prime Numbers
题目大意:这道题中给了一种数的定义,让求在某个区间内的这种数的个数。这种数的定义是:有且只有一个素因子的合数。
题目分析:这种数的实质是素数的至少两次幂。由此打表——打出最大区间里的所有这种数构成的表即可。
代码如下:
# 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的更多相关文章
- UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...
- 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.枚举所有的素数, ...
- 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项和, ...
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- Alexandra and Prime Numbers(思维)
Alexandra and Prime Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
随机推荐
- 手撕vue-cli配置——webpack.prod.conf.js篇
'use strict' const path = require('path') const utils = require('./utils') const webpack = require(' ...
- linux django 知识点 安装mysql数据库 和 pycharm
django 命令及相关知识点 1. 启动 pycharm 命令:sh pycharm.sh 2. 创建 django 项目 : django-admin.py startproject Hello ...
- 20145304 刘钦令 Exp2 后门原理与实践
20145304 刘钦令 Exp2 后门原理与实践 基础问题回答 (1)例举你能想到的一个后门进入到你系统中的可能方式? 浏览网页时,或许会触发网站中隐藏的下载代码,将后门程序下载到默认地址. 下载的 ...
- FJUT Home_W的gcd(乱搞)题解
题意: 给出一个序列a1,a2,a3,……an. HOME_W想在其中挖掘二元组,其中二元组的挖掘方法如下. 对于任意整数 l,r ,可得到一个二元组(l,gcd(al,al+1,……,ar)). H ...
- RedHat6使用CentOS yum源 换yum
yum 简单介绍一下 yum 主要功能是更方便的添加/删除/更新RPM 包,自动解决包的倚赖性问题,便于管理大量系统的更新问题. yum 可以同时配置多个资源库(Repository),简洁的配置文件 ...
- 【第十一章】 springboot + mongodb(简单查询)
1.mongodb在mac上的安装 下载mongodb,https://www.mongodb.org/ 解压缩到一个指定文件夹,如:/Users/enniu1/Desktop/zjg/mongodb ...
- 浅谈java中死锁问题
知识点:死锁的产生.死锁的实例 一:死锁的产生 我们在解决多线程共享资源的线程同步问题时,会使用synchronized关键字修饰方法或者通过Lock加锁方式修饰方法.代码块,防止多个线程访问统一资源 ...
- Linux下指定pip install和make install安装路径
在Linux下直接用pip install packageName,有些文件会被放到根目录下,如果没有sudo权限的话,是会安装失败的.这个以后我们就需要指定安装的目录了. pip install - ...
- 【Coursera】Technology :Fifth Week(2)
The Ethernet Story Bob Metcalfe Bob 参与了 Xerox 研究项目,着手解决建造一个处处连接个人计算机的架构.当时,他们刚刚完成了 Internet 的开端 -具有 ...
- 12_Python操作MySQL(basic)
""" Test connection to MySQL using mysql-client conn = MySQLdb.connect(host,port,user ...