bzoj1053

搜索

这种$n$很大并且跟约数有关的题都是搜索,因为约数每次除一下大概是$log$级的。

这道题我们希望一个数的约数个数尽量大才能成为反质数,所以涉及的因子不会很多

然后爆搜一发,枚举每个因子用不用,用几次,复杂度很低

#include<bits/stdc++.h>
using namespace std;
const int p[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; 
int n, ans = 1, c = 1;
void dfs(int k, long long tot, long long cnt) {
    if(k == 12) {
        return;
    }
    if(tot < ans && cnt >= c) {
        c = cnt;
        ans = tot;
    }
    if(tot > ans && cnt > c) {
        c = cnt;
        ans = tot;
    }
    long long t = p[k];
    for(int i = 1; i <= 20; ++i) {
        if(tot * t <= n) {
            dfs(k + 1, tot * t, cnt * (i + 1));
        } else {
            break;
        }
        t *= p[k];
    }
}
int main() {
    scanf("%d", &n);
    dfs(1, 1, 1);
    printf("%d\n", ans);
    return 0;
}
View Code

 

posted @ 2018-02-24 21:14  19992147  阅读(93)  评论(0编辑  收藏  举报