zoukankan      html  css  js  c++  java
  • 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
    ", ans);
        return 0;
    }
    View Code
  • 相关阅读:
    Run Shell Commands in Python
    在Linux系统上查找文件
    Build a Beautiful oh-my-zsh Themes
    Build VM Cluster on CentOS Host
    色彩学笔记
    Pr PS 笔记
    pthread 笔记
    图片格式
    win DLL 笔记
    XVS 操作
  • 原文地址:https://www.cnblogs.com/19992147orz/p/8467701.html
Copyright © 2011-2022 走看看