bzoj 1053: [HAOI2007]反素数ant && 51nod-1060:最复杂的数(反素数与因数个数计算)

问题概述:把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数。

例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6。如果有多个数复杂度相等,输出最小的

输入样例:                                       对应输出:

5                                                      1 1

1                                                      6 4

10                                                    60 12

100                                                  840 32

1000                                                7560 64

10000

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1060


定理1:对于一个大数可以分解质因数n = p1^a1*p2^a2*……*px^ax,其中pi表示第i小的质数,ai为pi的指数,

那么n的因数个数就为(a1+1)*(a2+1)*……*(ax+1);

反素数:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4,如果某个正整数x满足:对于任意

i(0<i<x),都有g(i)<g(x),则称x为反素数

性质一:一个反素数的质因子必然是从2开始连续的质数

性质二:反素数n = p1^a1*p2^a2*……*px^ax,其中必然a1>=a2>=a3……


此题相当于求小于n的最大反素数,可以用搜索解决

#include<stdio.h>
#include<algorithm>
using namespace std;
#define LL long long
LL n, ans, temp;
int a[26] = {0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
void Sech(int x, int p, int sum, LL now);
int main(void)
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		ans = 1;
		scanf("%lld", &n);
		Sech(1, 10, 1, 1);
		printf("%lld %lld\n", temp, ans);
	}
	return 0;
}

void Sech(int x, int p, int sum, LL now)
{
	int i;
	if(x>14)
	{
		if(sum>ans || sum==ans && now<temp)
			ans = sum, temp = now;
		return;
	}
	for(i=0;i<=p;i++)
	{
		Sech(x+1, i, sum*(i+1), now);
		if(now*a[x]/a[x]!=now || now*a[x]>n)
			return;
		now *= a[x];
	}
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值