UVa10539
http://vjudge.net/problem/UVA-10539
先打出来sqrt(n)以内的素数表,然后对于每个素数x,他对答案的贡献就是最大的p使x^p<=n,即log(x,n)。注意精度误差。
用1..r的减去1..l-1的就是答案。
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const int mxn=;
int pri[mxn],cnt=;
bool vis[mxn];
int num[mxn];
void Pri(){
cnt=;int i,j;
for(i=;i<mxn;i++){
if(!vis[i])pri[++cnt]=i;
for(j=;j<=cnt && i*pri[j]<mxn;j++){
vis[i*pri[j]]=;
if(i%pri[j]==)break;
}
}
return;
}
LL query(LL n){
LL ans=;
int i,j;
for(i=;i<=cnt && (LL)pri[i]*pri[i]<=n;i++){
ans+=log(n+0.1)/log(pri[i])-;
}
return ans;
}
int n;
LL l,r;
int main(){
Pri();
int T;
scanf("%d",&T);
while(T--){
scanf("%lld%lld",&l,&r);
printf("%lld\n",query(r)-query(l-));
}
return ;
}
UVa10539的更多相关文章
- UVA-10539 Almost Prime Numbers
题目大意:这道题中给了一种数的定义,让求在某个区间内的这种数的个数.这种数的定义是:有且只有一个素因子的合数. 题目分析:这种数的实质是素数的至少两次幂.由此打表——打出最大区间里的所有这种数构成的表 ...
随机推荐
- iOS 随机数(Fixed)
ios 有如下三种随机数方法: 1. srand((unsigned)time(0)); //不加这句每次产生的随机数不变 int i = rand() % 5; 2. ...
- NASM 之 helloworld1
SECTION .data msg: db "Hello World!", 0x0a len: equ $-msg SECTION .text global _main kerne ...
- CentOS 7.0关闭防火墙
.关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止fir ...
- 理解GloVe模型(Global vectors for word representation)
理解GloVe模型 概述 模型目标:进行词的向量化表示,使得向量之间尽可能多地蕴含语义和语法的信息.输入:语料库输出:词向量方法概述:首先基于语料库构建词的共现矩阵,然后基于共现矩阵和GloVe模型学 ...
- ios之UITextfield
//初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 13 ...
- React框架搭建单页面应用package.json基本包和依赖包
{ //依赖包 "devDependencies": { //babel "babel-core": "6.24.1", "bab ...
- CSS盒模型总结(一)
一.基本概念 盒子模型是css中一个重要的概念,理解了盒子模型才能更好的排版,盒模型的组成:content padding border margin 二.盒模型的分类 盒子模型有两种,分别是 ie ...
- jenkins学习笔记(一)
windows下安装jenkins步骤 1.下载 官网路径:https://jenkins.io/ 2.安装 直接双击安装程序即可 centos7下安装命令: wget -O /etc/yum.rep ...
- linux文件权限更改命令chmod及数字权限
chmod -change file mode bits :更改文件权限 chmod是用来改变文件或者目录权限的命令,但只有文件的属主和超级用户(root)才有这种权限. 更改文件权限的2种方式: 一 ...
- LeetCode 673. Number of Longest Increasing Subsequence
Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...