在一段区间[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的更多相关文章

  1. UVA294 约数 Divisors 题解

    Content 给定 \(n\) 个区间 \([l,r]\),求出每个区间内约数个数最大的数. 数据范围:\(1\leqslant l<r\leqslant 10^{10}\),\(r-l\le ...

  2. 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 ...

  3. 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 ...

  4. Divisors

    计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...

  5. Xenia and Divisors

    Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. hihocoder1187 Divisors

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...

  7. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  8. Sum of divisors

    Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...

  9. 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 ...

随机推荐

  1. The Django Book - 第四章 模板

    使用模板的最基本方式:1.根据原始模板代码字符串创建一个Template对象2. 使用字典创建一套Context变量3. 调用Template对象的render方法,传入Context变量参数 In ...

  2. 通过StringBuilder的reverse()实现倒序

    import java.util.Scanner; public class ReverseString { public static void main(String[] args) { Scan ...

  3. aspose.cell 给excel表格设置样式

    方法1: Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增样式 styleTitle.HorizontalAlignment ...

  4. 线段树成段更新模板POJ3468 zkw以及lazy思想

    别人树状数组跑几百毫秒 我跑 2500多 #include<cstdio> #include<map> //#include<bits/stdc++.h> #inc ...

  5. shell 简单脚本 2

    #!/bin/bash source /etc/profile APPLICATIONS_HOME="/cpic/cpicapp/cpic_analy/jars" APPLICAT ...

  6. spring框架的总结

    http://www.cnblogs.com/wangzn/p/6138062.html 大家好,相信Java高级工程师对spring框架都很了解吧!那么我以个人的观点总结一下spring,希望大家有 ...

  7. snprintf()返回值的陷阱

    int snprintf(char *restrict buf, size_t n, const char * restrict  format, ...); 函数说明:最多从源串中拷贝n-1个字符到 ...

  8. Web字节码(WebAssembly) Emscripten编译器安装

    首先你需要提前安装 git python 环境并且Ctrl+R输入cmd在windows的dos界面下能够运行 第一步: 在github上downloade下来emsdk git clone http ...

  9. [SDOi2012]Longge的问题 (数论)

    Luogu2303 [SDOi2012]Longge的问题 题目 题目背景 SDOi2012 题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N, ...

  10. UVa-12096-集合栈计算机

    这题的话,我们读入操作之后,首先对于空集就是初始化为空. 我们可以使用typedef 对于 set 重命名为Set,这样就可以直接用Set()的语法进行空集的初始化了. 这题主要是对于集合的处理,我们 ...