<span style="font-family:Courier New;font-size:18px;">对于任何正整数<img alt="" src="https://img-blog.csdn.net/20140505145329656" />,其约数个数记为<img alt="" src="https://img-blog.csdn.net/20140505145425281" />,例如<img alt="" src="https://img-blog.csdn.net/20140505145516187" />,如果某个正整数<img alt="" src="https://img-blog.csdn.net/20140505145329656" />满足:对任意的正整</span><p><span style="font-family:Courier New;font-size:18px;"> 数</span><span style="font-family:Courier New;font-size:18px;"><img alt="" src="https://img-blog.csdn.net/20140505145747812" />,都有<img alt="" src="https://img-blog.csdn.net/20140505145847078" />,那么称<img alt="" src="https://img-blog.csdn.net/20140505145329656" />为反素数。</span></p><p><span style="font-family:Courier New;font-size:18px;"></span> </p><p><span style="font-family:Courier New;font-size:18px;">从反素数的定义中可以看出两个性质:</span></p><p><span style="font-family:Courier New;font-size:18px;"></span> </p><p><span style="font-family:Courier New;font-size:18px;">(1)一个反素数的所有质因子必然是从2开始的连续若干个质数,因为反素数是保证约数个数为<img alt="" src="https://img-blog.csdn.net/20140505150741093" />的这个数<img alt="" src="https://img-blog.csdn.net/20140505145329656" />尽量小</span></p><p><span style="font-family:Courier New;font-size:18px;">(2)同样的道理,如果<img alt="" src="https://img-blog.csdn.net/20140505151209203" />,那么必有<img alt="" src="https://img-blog.csdn.net/20140505151330421" />这是优化关键
</span></p>
#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,int limit,ULL tmp,int num)
{
if(tmp > n) return;
if(num > best)
{
best = num;
ans = tmp;
}
if(num == best && ans > tmp) ans = tmp;
for(int i=1;i<=limit;i++)
{
double cur = (double)tmp;
if(n < cur*p[dept]) break;
dfs(dept+1,i,tmp *= p[dept],num*(i+1));
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
ans = INF;
best = 0;
dfs(0,60,1,1);
cout<<ans<<" "<<best<<endl;
}
return 0;
}
高效求反素数
最新推荐文章于 2022-08-08 19:51:45 发布