Mathematicians love all sorts of odd properties of numbers. For instance, they consider 945 to be an interesting number, since it is the first odd number for which the sum of its divisors is larger than the number itself.

To help them search for interesting numbers, you are to write a program that scans a range of numbers and determines the number that has the largest number of divisors in the range. Unfortunately, the size of the numbers, and the size of the range is such that a too simple-minded approach may take too much time to run. So make sure that your algorithm is clever enough to cope with the largest possible range in just a few seconds.

The first line of input specifies the number N of ranges, and each of the N following lines contains a range, consisting of a lower bound Land an upper bound U, where L and U are included in the range. L and U are chosen such that  and  .

For each range, find the number P which has the largest number of divisors (if several numbers tie for first place, select the lowest), and the number of positive divisors D of P (where P is included as a divisor). Print the text 'Between L and HP has a maximum of Ddivisors.', where LHP, and D are the numbers as defined above.

3
1 10
1000 1000
999999900 1000000000
Between 1 and 10, 6 has a maximum of 4 divisors.
Between 1000 and 1000, 1000 has a maximum of 16 divisors.
Between 999999900 and 1000000000, 999999924 has a maximum of 192 divisors. 题意:给你 a,b,让你找出 a,b之间因子最多的数是多少 b-a《=1000 我们枚举就好了
//meek
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include<map>
#include<queue>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair const int N=;
const ll INF = 1ll<<;
const int inf = ;
const int MOD = ; ll cal(ll x) {
ll hav = ;
for(ll i = ; i*i <= x; i++) {
if(x % i == ) hav ++;
if(x % i == && x / i != i) hav++;
}
return hav;
}
int main() {
int T;
ll a,b,ans,tmp;
scanf("%d",&T);
while(T--) {
ans = -;
scanf("%lld%lld",&a,&b);
for(ll i = a; i <= b; i++) {
ll temp = cal( i );
if(temp > ans) {
ans = temp;
tmp = i;
}
}
printf("Between %lld and %lld, %lld has a maximum of %lld divisors.\n",a,b,tmp,ans);
}
return ;
}

代码

UVA 294 - Divisors 因子个数的更多相关文章

  1. UVA - 294 Divisors【数论/区间内约数最多的数的约数个数】

    Mathematicians love all sorts of odd properties of numbers. For instance, they consider to be an int ...

  2. UVa 294 (因数的个数) Divisors

    题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...

  3. UVA - 294 Divisors (约数)(数论)

    题意:输入两个整数L,U(1<=L<=U<=109,U-L<=10000),统计区间[L,U]的整数中哪一个的正约数最多.如果有多个,输出最小值. 分析: 1.求一个数的约数, ...

  4. UVa 294 - Divisors 解题报告 c语言实现 素数筛法

    1.题目大意: 输入两个整数L.H其中($1≤L≤H≤10^9,H−L≤10000$),统计[L,H]区间上正约数最多的那个数P(如有多个,取最小值)以及P的正约数的个数D. 2.原理: 对于任意的一 ...

  5. Uva 294 Divisors(唯一分解定理)

    题意:求区间内正约数最大的数. 原理:唯一分解定义(又称算术基本定理),定义如下: 任何一个大于1的自然数 ,都可以唯一分解成有限个质数的乘积  ,这里  均为质数,其诸指数  是正整数.这样的分解称 ...

  6. UVA 294 294 - Divisors (数论)

    UVA 294 - Divisors 题目链接 题意:求一个区间内,因子最多的数字. 思路:因为区间保证最多1W个数字,因子能够遍历区间.然后利用事先筛出的素数求出质因子,之后因子个数为全部(质因子的 ...

  7. Divisors (求解组合数因子个数)【唯一分解定理】

    Divisors 题目链接(点击) Your task in this problem is to determine the number of divisors of Cnk. Just for ...

  8. Almost All Divisors(求因子个数及思维)

    ---恢复内容开始--- We guessed some integer number xx. You are given a list of almost all its divisors. Alm ...

  9. POJ 2992 Divisors (求因子个数)

    题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...

随机推荐

  1. Linux Shell Scripting Cookbook 读书笔记 6

    wget,curl, tar, rsync wget ftp://example.com/somefile.img -t 5 -O download.img -o log -t表示重试的次数 -O指定 ...

  2. Python环境设置-zlib not available

    今天在Linux中安Python3的时候,出现了一个错误:zipimport.ZipImportError: can‘t decompress data; zlib not available 网上找 ...

  3. html/css常用合集

    1. 消除inline-block元素间的换行间隙问题: {font-size:0;} 兼容IE6/7浏览器的方法:letter-spacing属性.   2.让两个inline-block的div顶 ...

  4. WPF 漏斗控件 等待沙漏效果

    由于WPF中不支持gif图片因此要实现一个漏斗沙漏效果有点小麻烦. 网上有一款开源的控件 理论上完全开源 官网 http://wpfspark.codeplex.com/贴一下效果图 大家感觉需要就在 ...

  5. 一个简单的js面试题

    在js群里看到有人发问,于是抱着练手的心态写了答了几个面试题,题目虽然不是太难,却很考验人的编程思维.汗颜,看了别人的答案后才发现自己好像笨了很多. 废话不说了 ,上代码. 1 要求 给一个数组的最后 ...

  6. js-字符串方法

    字符串 遍历字符串 方法:(类似数组) 使用for 或 for… in      结果:得到字符串中的每个字符 查找字符 ²  charAt(索引值) 注: 超出索引值范围时,则返回空字符 ²  ch ...

  7. MySQL 5.6 Reference Manual-14.1 Introduction to InnoDB

    14.1 Introduction to InnoDB 14.1.1 InnoDB as the Default MySQL Storage Engine 14.1.2 Checking InnoDB ...

  8. 文件被占用导致Hive Load文件不成功

    用Python写了个用LOAD命令将文件导入Hive的程序,开始代码写成下面这样: def loadToHive(bakFilePath, tbName): try: transport = TSoc ...

  9. 编译OpenCV遇到Qmake问题

    1.Ubuntu安装OpenCv,出现:qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or ...

  10. Functor、Applicative 和 Monad(重要)

    Functor.Applicative 和 Monad Posted by 雷纯锋Nov 8th, 2015 10:53 am Functor.Applicative 和 Monad 是函数式编程语言 ...