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 ...
随机推荐
- MIPS——递归调用
嵌套过程 不调用其他过程的过程称为叶过程(leaf procedure).如果所有过程都是叶过程,那么情况就很简单.但是某个过程可以调用其他过程,甚至调用的是自身的“克隆”.在调用非叶过程时使用寄存器 ...
- python中return和yield
def wx(): a = 'wx' b = '无邪' return a, b print(wx()) print(type(wx())) -----------执行结果--------------- ...
- ubuntu 升级到5.1kernel,打开bbr
apt-get -f install wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.1/linux-headers-5.1.0-0 ...
- SSH整合JAR包详解
如果要使用连接池,添加JAR : c3p0-0.9.1.2.jar
- Bootstrap历练实例:基本按钮组
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- layui和jquery冲突:Syntax error, unrecognized expression: +
问题 layui创建table数据表格,但点击第二页时控制台报错,错误信息如下: 解决方法 https://fly.layui.com/jie/24224/ http://www.layui.com/ ...
- UIScrollView和MultiThreading、UITextField、Keyboard
- Redis数据库(二)
1. Redis数据库持久化 redis提供了两种数据备份方式,一种是RDB,另外一种是AOF,以下将详细介绍这两种备份策略. 面试: 1.1 配置文件详解备份方式 [root@localhost ...
- python数据类型、字符编码、文件处理-练习
练习-字符串 # 写代码,有如下变量,请按照要求实现每个功能 (共6分,每小题各0.5分) name = " aleX" # ) 移除 name 变量对应的值两边的空格,并输出处理 ...
- python--FTP 上传视频示例
# 服务端 import json import socket import struct server = socket.socket() server.bind(('127.0.0.1',8001 ...