[CodeForces 27E] Number With The Given Amount Of Divisors (数论 + 反素数)

CodeForces - 27E

求约数个数为N的最小的数

这样的数一定是反素数,但不知道反素数也不要紧
用DFS从小到大枚举质数表中的每一个质数
然后乘起来,计算能组成的约数的个数
加两个剪枝,一是约数个数大于N的
二是继续增加这个质数的个数,但无法更新答案的

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef pair<int,int> Pii;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DBL;
typedef long double LDBL;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Pow2(a) (a*a)

const int tprm[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
int N;
ULL ans;

void dfs(int,int,ULL);

int main()
{
    scanf("%d", &N);
    ans=~0ULL;
    dfs(0,1,1);
    printf("%I64u\n", ans);
    return 0;
}

void dfs(int np, int cnt, ULL now)
{
    if(cnt>N) return;
    if(cnt==N) ans=min(ans, now);
    for(int i=1; i<64; i++)
    {
        if(ans/tprm[np]<now) break; // prune
        now*=tprm[np];
        dfs(np+1,cnt*(i+1),now);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值