Bzoj1053 [HAOI2007]反素数ant

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1053
题意:对于任何正整数 x ,其约数的个数记作 g(x)。例如 g(1)=1 g(6)=4 。如果某个正整数 x 满足:g(x)>g(i) 0<i<x,则称 x 为反质数。例如,整数 1246 等都是反质数。现在给定一个数 N ,你能求出不超过 N 的最大的反质数么?
题解: 实际要求的是不大于 N <script type="math/tex" id="MathJax-Element-44">N</script> 的因数最多的最小的数是多少,因为要因数最多,所以取小的质因数一定比大的质因数更优,所以可以脑补两个性质:
  1.答案的质因数分解一定是连续的前若干个质数。
  2.答案的质因数分解指数从小到大递减
所以就变成了一个暴搜加两个剪枝。

#include<bits/stdc++.h>
int p[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
long long n, ans_num, ans;
void dfs(int dep, int last, long long num, long long now) {
    if (now > n) return;
    if (dep < 0) {if (num > ans_num || num == ans_num && now < ans) ans_num = num, ans = now; return;}
    for (int i = 1; i <= last && now <= n; i++) now *= p[dep];
    for (int i = last; now <= n; i++, now *= p[dep])
        dfs(dep - 1, i, num * (i + 1), now);
}
int main() {
    scanf("%lld", &n);
    dfs(9, 0, 1, 1);
    printf("%lld\n", ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值