问题概述:把一个数的约数个数定义为该数的复杂程度,给出一个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];
}
}