ZOJ 2562 More Divisors

传说中的传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1562

More Divisors

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Everybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is often not very convenient, ten has only four divisors -- 1, 2, 5 and 10. Thus, fractions like 1/3, 1/4 or 1/6 have inconvenient decimal representation. In this sense the notation with base 12, 24, or even 60 would be much more convenient.

The main reason for it is that the number of divisors of these numbers is much greater -- 6, 8 and 12 respectively. A good quiestion is: what is the number not exceeding n that has the greatest possible number of divisors? This is the question you have to answer.

Input:

The input consists of several test cases, each test case contains a integer n (1 <= n <= 1016).

Output:

For each test case, output positive integer number that does not exceed n and has the greatest possible number of divisors in a line. If there are several such numbers, output the smallest one.

Sample Input:
 
10
 20
 100
Sample Output:
 
6
12
60

Author: Andrew Stankevich
Source: Andrew Stankevich's Contest #4

反素数:反素数第一点:g(x)表示 x含有因子的数目,设 0<i<=x  则g(i)<=x;

反素数第二个特性:2^t1*3^t2^5^t3*7^t4..... 这里有 t1>=t2>=t3>=t4...

 

 
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long int LL;

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

LL bestsum,bestnum,n;

void dfs(LL cur,LL sum,LL x,LL lim)
{
    if(cur>n) return;
    if(sum>bestsum)
    {
        bestsum=sum;
        bestnum=cur;
    }
    if(sum==bestsum&&cur<bestnum)
    {
        bestnum=cur;
    }

    LL ret=1;
    for(int i=1;i<=lim;i++)
    {
        ret=ret*pri[x];
        if(ret*cur>n)
            break;
        else
            dfs(cur*ret,sum*(i+1),x+1,i);
    }
}

int main()
{
while(scanf("%lld",&n)!=EOF)
{
    bestsum=0;
    dfs(1LL,1LL,0,50);
    printf("%lld ",bestnum);
}
    return 0;
}
* This source code was highlighted by YcdoiT. ( style: Autumn )



原文地址:https://www.cnblogs.com/CKboss/p/3350911.html