逆素数本质就是想让数值最小并且因子数量最多。
逆素数的条件就是逆素数x 在0<i<x中所有的i的约数的个数都小于x的约数的个数。
x可以被分解为x=a1b1 *a2b2 *…
x的因子个数就是(b1+1) * (b2+1)*…
这里注意一下若区间较短不存在逆素数就直接暴力就好了 注意O(n)的判因子的方法。
代码环节:
//god with me
//#pragma GCC optimize(1)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define inf 0x7fffffff
//#define ll long long
#define int long long
//#define double long double
//#define double long long
#define re int
//#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define mk make_pair
#define P pair < int , int >
#define pd pair <double,double>
#define x first
#define y second
#define db double
using namespace std;
const int mod=4933;
//const int inf=1e18;
const int M=1e8;
const int N=1e5+5;//??????.???? 4e8
//反素数
int l,r;
int ans,maxn;
int prime[]={2,3,5,7,11,13,17,19,23,29};
int divide(int n)
{
int num=1;
for(int i=2;i<=sqrt(n);i++)
{
if(n%i==0)
{
num++;
int temp=n/i;
if(n%temp==0&&temp!=i)num++; //求反就是跟他相积为n的另一个数,判断是不是平方
}
}
if(n!=1)num++;
return num;
}
void dfs(int deep,int arr,int cur,int num) //质数层数 当前质数最大质数 因子个数 当前的质数之积
{
if(cur>maxn||(cur==maxn&&num<ans))
{
maxn=cur,ans=num;
}
if(deep>8)return; //原因是质数单个乘积超范围
for(int i=1;i<=arr;i++) //从1开始因为后面可能是0
{
num*=prime[deep];
if(num>r) return;
dfs(deep+1,i,(i+1)*cur,num);
}
}
void solve()
{
cin>>l>>r;
if(r-l<100000)
{
for(int i=l;i<=r;i++)
{
int cnt=0;
cnt=divide(i);
if(cnt>maxn)
{
maxn=cnt;
ans=i;
}
}
cout<<"Between "<<l<<" and "<<r<<", "<<ans<<" has a maximum of "<<maxn<<" divisors.";
}
else
{
dfs(0,31,1,1);
cout<<"Between "<<l<<" and "<<r<<", "<<ans<<" has a maximum of "<<maxn<<" divisors.";
}
}
signed main()
{
int T=1;
// cin>>T;
for(re index=1;index<=T;index++)
{
solve();
}
return 0;
}