Spoj-ODDDIV Odd Numbers of Divisors
Given a positive odd integer K and two positive integers low and high, determine how many integers between low and high contain exactly K divisors.
Input
The first line of the input contains a positive integer C (0<C<100,000), the number of test cases to follow. Each case consists of a line containing three integers: K, low, and high (1<K<10000, 0<low≤ high<10^10). K will always be an odd integer.
Output
Output for each case consists of one line: the number of integers between low and high, inclusive, that contain exactly K divisors.
Example
Input:
3
3 2 49
9 1 100
5 55 235 Output:
4
2
1
询问一组(k,l,r),意思是在数字l到r之间有多少个数字有奇数个因子
显然如果对一个x质因数分解成(大π) pi^qi 那么总因子数是(大π) (qi+1)
因为它有奇数个因数,所以所有qi都是偶数,所以x应当是完全平方数!
因此,只要枚举x,而且l和r的范围从1e10将到1e5
把一个询问(k,l,r)差分成(k,1,r)-(k,1,l-1),就可以离线搞了
然后直接从1到10w枚举每个x,计算x^2有多少个因子,更新对于一个k,当前1~k已经记录了多少个完全平方数
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
LL l,r,k,n;
int mx;
bool isprime[];
int sum[];
struct ask{int k,n,rnk;}q[];
bool operator <(ask a,ask b){return a.n<b.n;}
int cnt[];
int ans[];
inline void init()
{
memset(isprime,,sizeof(isprime));
for (int i=;i<=;i++)sum[i]=;
isprime[]=isprime[]=;
int k,l;
for (int i=;i<=;i++)
{
if (isprime[i])
{
sum[i]=;
for (int j=;i*j<=;j++)
{
isprime[i*j]=;k=;l=j;
while (l%i==){l/=i;k++;}
sum[i*j]*=*k+;
}
}
}
}
int main()
{
init();
n=read();
for (int i=;i<=n;i++)
{
int x=read(),y=ceil(sqrt(read())),z=floor(sqrt(read()));
mx=max(mx,z);
q[*i-].k=x;q[*i-].n=y-;q[*i-].rnk=-i;
q[*i].k=x;q[*i].n=z;q[*i].rnk=i;
}
sort(q+,q+*n+);
int now=;
for (int i=;i<=mx;i++)
{
cnt[sum[i]]++;
while (now<=*n&&q[now].n==i)
{
if (q[now].rnk>)ans[q[now].rnk]+=cnt[q[now].k];
else ans[-q[now].rnk]-=cnt[q[now].k];
now++;
}
}
for (int i=;i<=n;i++)printf("%d\n",ans[i]);
}
Spoj ODDDIV
Spoj-ODDDIV Odd Numbers of Divisors的更多相关文章
- Odd Numbers of Divisors
给出一个正奇数K,两个正整数low,high. 有多少整数属于[low, high],且包含K个因子. 数据 C(0 < C < 1e5),测试样例数. (1 < K < 10 ...
- SPOJ BALNUM - Balanced Numbers - [数位DP][状态压缩]
题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1 ...
- SPOJ - BALNUM Balanced Numbers(数位dp+三进制状压)
Balanced Numbers Balanced numbers have been used by mathematicians for centuries. A positive integer ...
- SPOJ - BALNUM - Balanced Numbers(数位DP)
链接: https://vjudge.net/problem/SPOJ-BALNUM 题意: Balanced numbers have been used by mathematicians for ...
- SPOJ BALNUM Balanced Numbers (数位dp)
题目:http://www.spoj.com/problems/BALNUM/en/ 题意:找出区间[A, B]内所有奇数字出现次数为偶数,偶数字出现次数为计数的数的个数. 分析: 明显的数位dp题, ...
- SPOJ #429 Simple Numbers Conversion
This is simply a human work simulation - exactly reproducing how you do it by hand. Nothing special. ...
- spoj 10606 Balanced Numbers 数位dp
题目链接 一个数称为平衡数, 满足他各个数位里面的数, 奇数出现偶数次, 偶数出现奇数次, 求一个范围内的平衡数个数. 用三进制压缩, 一个数没有出现用0表示, 出现奇数次用1表示, 出现偶数次用2表 ...
- [创意标题] spoj 11354 Amusing numbers
意甲冠军: 给k(1<=k<=10^15),先询问k 大只包含数字5和6的数目是多少 实例 1那是,5 ,3那是,55 .4那是,56 思考: 首先,我们可以找到.有许多2这是头号,有两个 ...
- [数位dp] spoj 10738 Ra-One Numbers
题意:给定x.y.为[x,y]之间有多少个数的偶数位和减去奇数位和等于一. 个位是第一位. 样例: 10=1-0=1 所以10是这种数 思路:数位dp[i][sum][ok] i位和为sum 是否含有 ...
随机推荐
- Perl 输出内容到 excel
可以参考: http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel.pm 使用Spre ...
- (八)VMware harbor 成员管理
(一)VMware harbor 成员管理 可以给项目添加成员,成员必须是已经注册的成员. 添加成员后,成员就会有4种角色:项目管理员,维护人员,开发人员,访客. 1.1 新建成员 1.2 修改角色 ...
- video 的使用
video ui给了默认的暂停图片 利用video自身的属性很难达到效果 这里自己写了个 简单记录下 <div class="cg-container video-img" ...
- Java Miniui实现批量上传文件demo 201906221520
可能需要的jar包: 需要miniui(类似easyui). Test2019062201.jsp <%@ page language="java" contentType= ...
- iOS利用UIDocumentInteractionController和Quick Look打开或预览文档
在App的开发过程中,我们避免不了要打开软件中的文件,例如:Excel文件,Word文件,图片文件等不同格式的文件或者想要通过第三方的App来打开这些文件,那么我们就要用到UIDocumentInte ...
- python爬虫基础08-selenium大全2/8-Chrome Webdriver启动选项
Selenium笔记(2)Chrome Webdriver启动选项 本文集链接:https://www.jianshu.com/nb/25338984 在Selenium中使用不同的Webdriver ...
- selenium.common.exceptions.WebDriverException: Message: u'unknown error: cannot get automation extension\nfrom unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfeb
Python2.7 selenium3.4.1在使用chrome driver时报错:selenium.common.exceptions.WebDriverException: Message: u ...
- Day08字符编码
Day08: 知识储备: 硬盘:由硬盘加载到内存,cpu从内存中取 软件产生的数据都是先保存在内存中 文件,输入文字,保存到内存,内存是硬件,硬件只能保存2进制,所以需要转换 文本编辑器,输入文字的时 ...
- (原)pat1007素数猜想
---恢复内容开始--- 1007. 素数对猜想 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 让我们 ...
- boot_mem分配器
#define alloc_bootmem_low_pages(x) \ __alloc_bootmem_low(x, PAGE_SIZE, ) void * __init __alloc_bootm ...