Description

正整数x 的约数是能整除x 的正整数。正整数x的约数个数记为div(x)。例如,1,2,5,10 都是正整数10的约数,且div(10)=4。设a 和b是2 个正整数,a≤b,找出a 和b之间约数个数最多的数x。对于给定的2 个正整数a≤b,计算a 和b之间约数个数最多的数。

Input

输入数据的第1行有2个正整数a和 b,a≤1000000000,b≤1000000000。

Output

若找到的a 和b之间约数个数最多的数是x,将div(x)输出。

Sample Input

1 36

Sample Output

9

其他测试数据:

1 36
9 1000000 2000000
288 999998999 999999999
1024 1 1000000000
1344 100 1000000000
1344 666 666666666
1200

这一题卡了一阵子了,是在看不懂,琢磨不明白书上的代码了,只能照抄了。。。

正整数x可以分解为质因子之积:

$$ x = p_1^{N_1} * p_2^{N_2} * p_3^{N_3} * ... * p_k^{N_k} $$

所以约数div的公式为:

$$ div(x) = (N_1 + 1)(N_2 + 1)...(N_k + 1) $$

期间还参考了:

  1. https://blog.csdn.net/Will_Lee_Buaa/article/details/8513265?utm_source=blogxgwz7

    感觉这个有点问题,测试数据没过

  2. https://blog.csdn.net/Tc_To_Top/article/details/43698997?utm_medium=distribute.pc_relevant.none-task-blog-title-1&spm=1001.2101.3001.4242

    这个也没看太明白。。

  3. https://blog.csdn.net/changshu1/article/details/47293659?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-2.channel_param

    这个注释写的多

我自己写的AC代码:

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int lift;
int right;
lift = cin.nextInt();
right = cin.nextInt();
MaxDiv maxDiv = new MaxDiv();
MaxDiv.primes();
if (lift == 1 && right == 1) {
MaxDiv.max_num = 1;
MaxDiv.numb = 1;
} else {
MaxDiv.max_num = 2;
MaxDiv.numb = 1;
MaxDiv.search(1, 1, 1, lift, right);
}
System.out.println(MaxDiv.max_num);
/*System.out.println(MaxDiv.numb);*/
}
} class MaxDiv {
public static int max_num; // 存最多的质因子个数
public static int numb; // 存质因子最多的数
public final static int MAXP = 31622; // 普通数组最大的大小
public final static int PCOUNT = 3401; // 素数数组最大的大小
public static int prime[] = new int[PCOUNT + 1]; // 素数数组 // 欧拉筛法求素数表
public static void primes() {
int k = 0;
boolean num[] = new boolean[MAXP + 1];
for (int i = 2; i <= MAXP; i++) {
num[i] = true;
}
for (int i = 2; i <= MAXP; i++) {
if (num[i]) {
prime[++k] = i;
}
for (int j = 1; j <= k && prime[j] * i <= MAXP; j++) {
num[prime[j] * i] = false;
}
}
} // 这个函数没明白, 照抄书上的
public static void search(int from, int tot, int num, int low, int up) {
if (num >= 1)
if ((tot > max_num) || ((tot == max_num) && (num < numb))) {
max_num = tot;
numb = num;
}
if (low == up && low > num)
search(from, tot * 2, num * low, 1, 1);
for (int i = from; i <= PCOUNT; i++) {
if (prime[i] > up)
return;
else {
int j = prime[i];
int x = low - 1;
int y = up;
int n = num, t = tot, m = 1;
// 应该是循环除质因子
while (true) {
m++;
t += tot;
x /= j;
y /= j;
if (x == y)
break;
n *= j;
search(i + 1, t, n, x + 1, y);
}
m = 1 << m;
if (tot < max_num / m)
return;
}
}
}
}

最新文章

  1. 部署点评Cat监控项目(转)
  2. [前端]使用JQuery UI Layout Plug-in布局 - wolfy
  3. npm淘宝镜像
  4. 各种 starter poms (启动器)
  5. Android笔记——Android中数据的存储方式(一)
  6. 由window.history.back()引发的问题
  7. 解同余式ax ≡ c(mod m)
  8. libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.9-1.el6.x86_64
  9. javascript 弹出的窗口返回值给 父窗口
  10. C#中OpenFileDialog的使用
  11. Android应用程序消息处理机制(Looper、Handler)分析
  12. Android Volley 之自定义Request
  13. python selenium+phantomjs alert()弹窗报错
  14. 二)Spring AOP编程思想与动态代理
  15. sass报 error (Line XX: Invalid GBK character &quot;\xE4&quot;) 的解决办法
  16. Wyn BI的机会在哪里:越靠近消费者的行业,比如零售、文娱和金融,信息化投入越大 ZT
  17. 【CF1139D】Steps to One(动态规划)
  18. python编码,赋值和is的区别
  19. eclipse配置servlet错误
  20. opacity设定图片透明度

热门文章

  1. Java9系列第6篇-Stream流API的增强
  2. 【Flutter 混合开发】与原生通信-BasicMessageChannel
  3. 自学Python可以吗?怎样从入门到大师?我写这篇文章告诉你
  4. docker compose 用法
  5. pyqt5安装报错解决办法
  6. B. Psychos in a Line 解析(思維、單調棧)
  7. vue-cli中使用swiper
  8. nginx处理vue打包文件后的跨域问题
  9. 如何对List集合中的对象进行按某个属性排序
  10. final,static,this,super 关键字总结