反素数的定义:对于任何正整数,其约数个数记为,例如,如果某个正整数满足:对任意的正整
数,都有,那么称为反素数。
从反素数的定义中可以看出两个性质:
(1)一个反素数的所有质因子必然是从2开始的连续若干个质数,因为反素数是保证约数个数为的这个数尽量小
(2)同样的道理,如果,那么必有
在ACM竞赛中,最常见的问题如下:
(1)给定一个数,求一个最小的正整数,使得的约数个数为
(2)求出中约数个数最多的这个数
类型一:
题目:http://codeforces.com/problemset/problem/27/E
题意:给一个数,求一个最小的正整数,使得它的因子个数为。
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
LL p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; //素数打表
LL ans;
LL N;
void dfs(LL dept,LL x,LL n)//dept 素因子的位置 x 当前的最优解 n因子个数
{
if(n>N)
return;
if(n==N&&x<ans)// 得到最小的值
ans=x;
for(int k=1;k<=65;k++){ //p[i]^60;
if(ans/p[dept]<x) break;//减枝 当ans<p[dept]*x的时候 明显不是最优解 不必要继续计算
dfs(dept+1,x*=p[dept],n*(k+1));//n*(k+1)为当前的因子数
//因为每乘一次p[dept] 分解时的指数+1;
// 因子个数为每个素因子的指数+1 相乘;
}
}
int main()
{
while(cin>>N){
ans = 5e18;
dfs(0,1,1);
cout<<ans<<endl;
}
return 0;
}
类型二:
题目:http://acm.timus.ru/problem.aspx?space=1&num=1748
题意:求出中约数个数最多的这个数
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
typedef unsigned long long ULL;
const ULL INF = ~0ULL;
int p[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
ULL ans,n;
int best;
void dfs(int dept,ULL tmp,int num)//dept 素数表的位置(搜索的根节点)
{ // tmp 当前的最优解 num 因子个数
//到叶子结点,返回
if(dept >= 16) return;
if(num > best)//更新最优解
{
best = num;
ans = tmp;
}
//当因子个数相同时,取值最小的
if(num==best&&ans>tmp)
ans=tmp;
for(int i=1;i<=63;i++){
if(n/p[dept]<tmp)
break;
dfs(dept+1,tmp*=p[dept],num*(i+1));
}
}
int main()
{
while(cin>>n){
ans=INF;
best=0;
dfs(0,1,1);
cout<<ans<<endl;
}
return 0;
}