题目描述

正整数 x 的约数是能整除x的正整数,其约数的个数记为div(x),例如div(10)=4。设 a 和 b 是两个正整数,找出 a 和 b 之间(包含a,b)约数个数最多的数 x 的约数个数

 

输入

两个正整数a和b,(1<=a<=b<=1e5)

 

输出

一个正整数表示答案。

 

样例输入

1 36

 

样例输出

9

 


 

 

【方法1】线性筛

 1 /*
 2     Test1 : 线性筛的做法
 3 */
 4 #include<bitset>
 5 #include<cstdio>
 6 #include<iostream>
 7 using namespace std;
 8 typedef long long ll;
 9 const int N = 1e6+10;
10  
11 int Prime[N],Cnt[N];
12 bool is_prime[N];
13 int A,B,Ans=2;
14  
15 int Count_Prime ( int x , int p ){
16     int tot = 0 ;
17     while( x % p == 0 ){
18         tot ++ ;
19         x /= p ;
20     }
21     return tot ;
22 }
23  
24 void Is_prime(){
25     //memset( is_prime , 0 , sizeof(is_prime) );
26     for(int i=1;i<N;i++) Cnt[i] = 1 ;
27     for(int i=2;i<N;i++){
28         if( !is_prime[i] ){
29             for(int j=i*2 ; j < N ; j+=i ){
30                 Cnt[j] *= ( Count_Prime( j , i ) + 1 ) ;
31                 is_prime[j] = true ;
32                 if( A <= j && j <= B ){
33                     if( Ans < Cnt[j] )
34                         Ans = Cnt[j] ;
35                 }
36             }
37         }
38     }
39 }
40 int main()
41 {
42     scanf("%d%d",&A,&B);
43     Is_prime() ;
44     /*
45     for(int i=A;i<=B;i++){
46         printf("%d , %d\n",i,Cnt[i]);
47     }
48     */
49     if( A == B && A == 1 ) Ans = 1 ;
50     printf("%d\n",Ans);
51     return 0;
52 }
View Code

相关文章:

  • 2021-11-27
  • 2021-11-27
  • 2021-06-26
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-08-26
相关资源
相似解决方案