zoj 2562

反素数的一些知识:

反素数是<=n的数中质因子数最多的并且最小的。

故有一下两个结论:

1.反素数必然是从2开始连续的若干个素数的若干幂的积:因为假设2*3*7*9,则一定存在2*3*5*7<2*3*7*9;

2.反素数的因子的幂,质因子越小,质因子的幂越大:因为假设2^4*3^6,必小于2^6*3^4,而它们的约数个数相同,都是(4+1)*(6+1);

具体看代码,一开始设的50是因为2^50已经大于10^16;

//============================================================================
// Name        : zoj2562.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;


long long ans, anssum, n;

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

void dfs(long long curans,int now, long long cursum, int limit){
	if(cursum > anssum){
		ans = curans;
		anssum = cursum;
	}
	else if(cursum == anssum&&curans < ans){
		ans = curans;
	}
	if(now > 14) return ;
	long long temp = curans;
	for(int i = 1;i <= limit;i++){
		if(curans*prime[now] > n){
			break;
		}
		curans *= prime[now];
		dfs(curans, now+1, cursum*(i+1), i);
	}
}


int main(){
	freopen("a.txt", "r", stdin);
	while(scanf("%lld", &n)!=EOF){
		ans = 1000000000000000;
		anssum = 1;
		dfs(1, 0, 1, 50);
		printf("%lld\n", ans);
	}
	return 0;
}

  

转载于:https://www.cnblogs.com/ACKOKO/articles/2115848.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值