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 ...
随机推荐
- 上下文 xx
上下文,就是指在程序中的某个位置,可以访问到的所有资源的总和. 具体说来,在程序中资源可能是一个变量.一个常量.一个类的引用等等.
- winform中让显示的图片覆盖到父窗体保持父窗体的不可选中的状态,且任务栏中不会显示子窗体的任务选项
要求:为父窗体添加一个类似于加载等待的功能,当窗体点击备份时弹出且覆盖掉窗体 问题一产生:当为弹窗添加控件时,form.show();导致窗体卡死,控件变得透明化; 问题一分析:当窗体show();之 ...
- 如何关闭OSX 10.11 SIP (System Integrity Protection)
http://www.jianshu.com/p/0572336a0771 注意:SIP功能是Apple在OSX上推出的系统完整性保护功能,对于普通MAC用户来说是一项安全保护功能,如果不了解他的作用 ...
- House of Spirit(fastbin)
0x01 fastbin fastbin所包含chunk的大小为16 Bytes, 24 Bytes, 32 Bytes, … , 80 Bytes.当分配一块较小的内存(mem<=64 Byt ...
- Bootstrap历练实例:带有下拉菜单的标签和胶囊导航
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- Bootstrap历练实例:大的按钮
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...
- shell脚本调试打印日志问题
shell脚本调试打印日志问题 1. 需求 我们在编写脚本的时候,有时候需要做调试,便于我们定位问题,有时候等脚本上线之后,我们需要保留脚本执行过程中的记录.便于我们在出问题的时候,定位问题. 2. ...
- Xcode的Git管理
在Xcode中创建工程的时候,我们很容易的可以将新创建的工程添加到Git中,如图: 但是如果是本地已经有的工程,那该如何添加到Git中呢? 首先终端进入到该工程的目录. 然后: git init gi ...
- java面试宝典第二弹
arraylist和linklist的区别,hashmap和hashset的区别,常用的集合有哪些 一.基础内容 容器就是一种装其他各种对象的器皿.java.util包 容器:Set, List, M ...
- abaqus二次开发概述
说明 abaqus二次开发概述 导语 用户子程序特点 abaqus用户程序接口与调用方式 abaqus用户子程序分类 常用用户子程序介绍 Refence 说明 本系列文章本人基本没有原创贡献,都是在学 ...