zoj 2562 More Divisors(反素数)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1562

题意:求小于等于n(1 <= n <= 1016)的约数个数最多的数。


反素数

根据反素数的定义,这个题就是让求最大的反素数。

反素数搜索的依据的两个重要的性质:

反素数的质因子是从2开始的连续的素数;

p=2^t1*3^t2*5^t3*7^t4.....必然t1>=t2>=t3>=....

另外一个性质:对于p=2^t1*3^t2*5^t3*7^t4.....,p的因子的个数为(t1+1)*(t2+1)......*(tn+1)。

因为n最大是10^16,因此t最大可以为54,根据以上性质枚举每一个素数以及每一个素数的个数进行搜索。


#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#include <algorithm>
#define LL long long
#define _LL __int64
#define eps 1e-12
#define PI acos(-1.0)
using namespace std;

LL n;
int prime[20] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};

LL Maxcur; //当前最大的反素数
int Maxcnt;//最大反素数对应的因子个数

void get_antiprime(LL cur, int cnt, int Maxnum, int k)
{
	if(cur > n)
		return;
	if(cnt > Maxcnt)
	{
		Maxcnt = cnt;
		Maxcur = cur;
	}
	if(cnt == Maxcnt && cur < Maxcur)
	{
		Maxcur = cur;
	}
	LL tmp = cur;
	//枚举第K个素数的个数
	for(int i = 1; i <= Maxnum; i++)
	{
		tmp *= prime[k];
		if(tmp > n)
			return;
		get_antiprime(tmp,cnt*(i+1),i,k+1);
	}
}

int main()
{
	while(~scanf("%lld",&n))
	{
		Maxcur = 1;
		Maxcnt = 1;
		get_antiprime(1,1,54,0);
		printf("%lld\n",Maxcur);
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值