ZOJ2562

来源:互联网 发布:qq会员永久软件 编辑:程序博客网 时间:2024/05/20 10:20

关于反素数的一道题(这里分析的很好http://blog.csdn.net/ACdreamers/article/details/25049767)

首先是反素数的概念:对任意的正整,都有,那么称为反素数。

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

2如果,那么必有

本题的意思:求出中约数个数最多的这个数

#include<iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <cstdio>
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef unsigned long long ULL;
const ULLINF = ~0ULL;
int p[16]= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
ULL ans,n;
int best;
void dfs(ULLtmp,int num,int k)//num表当前的约数个数,tmp指当前的数
{
    if(k>15)return;
    if(num>best){ans=tmp;best=num;}
    if(num==best&&tmp<ans)ans=tmp;
    for(int i=1;i<=63;i++)
    {
        if(tmp*p[k]>n)break;
        dfs(tmp*=p[k],num*(i+1),k+1);
    }
    return;
}
int main()
{
    while(cin>>n)
    {
        ans=INF;
        best=0;
        dfs(1,1,0);
        cout<<ans<<endl;
    }
    return 0;
}


0 0
原创粉丝点击