UVa294 Divisors
在一段区间[l,r]内,找出因数最多的数的个数以及其因数个数。
用唯一分解定理将一个数分解成质因数的乘积,例如 2^p1*3^p2*5^p3*7^p4*.... 从这些质因数中任选出一些数相乘,都可以组成原数的因数,总方案数为(p1+1)*(p2+1)*(p3+1)*... 注:+1是因为可以不选,全部不选的话得到数字1,也是原数的因数。
r<=1000000000,对其开根号得到31622,也就是说不会存在两个以上大于31622的质因数。素数筛算出1~3w+的质数。接下来用唯一分解定理算出区间内每个数的因数个数←暴力扫描即可。(0 ≤ L − R ≤ 10000)10000*30000次计算(实际到不了这么多),并不会炸。
/*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;
}
int dvi(int a){//计算因数个数
int res=;
int i,j;
int time=;
for(i=;i<=cnt && a>;i++){
time=;
while(a%pri[i]==){
time++;
a/=pri[i];
}
res*=(time+);
}
if(a>)res*=;
return res;
}
int l,r;
int main(){
Pri();
int i,j;
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&l,&r);
int pos=l;
int mx=dvi(l);int tmp;
for(i=l+;i<=r;i++){
tmp=dvi(i);
if(tmp>mx){
mx=tmp;
pos=i;
}
}
printf("Between %d and %d, %d has a maximum of %d divisors.\n",l,r,pos,mx);
}
return ;
}
UVa294 Divisors的更多相关文章
- UVA294 约数 Divisors 题解
Content 给定 \(n\) 个区间 \([l,r]\),求出每个区间内约数个数最大的数. 数据范围:\(1\leqslant l<r\leqslant 10^{10}\),\(r-l\le ...
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- HDU - The number of divisors(约数) about Humble Numbers
Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...
- Divisors
计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...
- Xenia and Divisors
Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- hihocoder1187 Divisors
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
随机推荐
- 激活 IDEA, PyCharm
1. 到网站 http://idea.lanyus.com/ 获取注册码. 2.填入下面的license server: http://intellij.mandroid.cn/ http://ide ...
- WINDOWS-基础:WINDOWS常用API
1.窗口信息 //MS 为我们提供了打开特定桌面和枚举桌面窗口的函数. hDesk=OpenDesktop(lpszDesktop,,FALSE,DESKTOP_ENUMERATE); //打开我们默 ...
- selenium-介绍和安装
前戏 相信大家对web自动化selenium都不陌生,是一个web自动化框架,我在第一家公司的时候,产品是两个星期一个版本,每一次发布测试都要进行回归测试,也就是大家说的点点点,后来我就想,能不能做成 ...
- Java产生GUID
/** * 产生GUID */public static final String generateGUID(){ UUID uuid = UUID.randomUUID(); return uuid ...
- NOIP 2017 图书管理员
题目描述 图书馆中每本书都有一个图书编码,可以用于快速检索图书,这个图书编码是一个 正整数. 每位借书的读者手中有一个需求码,这个需求码也是一个正整数.如果一本书的图 书编码恰好以读者的需求码结尾,那 ...
- docker-compose volumes指令路径映射问题
背景:最近在自学docker容器知识,在跟着<Docker - 从入门到实践>进行 docker-compose 搭建django/postgreSQL 实例.在搭建过程中由于自己操作失误 ...
- 【OS_Linux】Linux下软件的安装与卸载
1.Linux中软件安装包的分类 1) 一类是可执行的软件包,无需编译直接安装.在Windows中所有的软件包都是这种类型.安装完这个程序后,你就可以使用,但你看不到源程序.而且下载时要注意这个软件是 ...
- 【php】类型转换
$a = 9; print_r((array) $a) ; 输出: [0=>9] print_r((array) null); 输出: []
- ThreadLocalClient小应用
今天遇到hibernate.find就会进行权限配置,如果某处想要跳过权限配置,则可以如下 ThreadLocalClient.get().envParamMap.put(DataAuthority. ...
- return_url notify_url
return_url对返回订单状态进行更新和判断,notify_url为异步调动页面,需要先判断notify_url里是否对订单数据做过处理,避免重复更新数据,然后如果用户付款成功直接关闭页面,会造成 ...