zoukankan      html  css  js  c++  java
  • 【BZOJ】1053: [HAOI2007]反素数ant

    题解

    从每个质因子小到大指数非严格递减,直接搜就行

    代码

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define MAXN 100005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    template<class T>
    void read(T &res) {
        res = 0;char c = getchar();T f = 1;
        while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
        }
        while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {out(x / 10);}
        putchar('0' + x % 10);
    }
    int N,ans,res;
    int prime[MAXN],tot;
    bool isprime[MAXN];
    void dfs(int pos,int val,int pre,int cnt) {
        if(cnt <= ans && val > res) return;
        if(cnt > ans) {
    	res = val;
    	ans = cnt;
        }
        else if(cnt == ans && val < res) res = val;
        int t = 1;
        for(int i = 1 ; i <= pre ; ++i) {
    	t = t * prime[pos];
    	if(val > N / t) break;
    	dfs(pos + 1,val * t,i,cnt * (i + 1));
        }
    }
    void Solve() {
        read(N);
        for(int i = 2 ; i <= 100000 ; ++i) {
    	if(!isprime[i]) {
    	    prime[++tot] = i;
    	}
    	for(int j = 1 ; j <= tot ; ++j) {
    	    if(prime[j] > 100000 / i) break;
    	    isprime[i * prime[j]] = 1;
    	    if(i % prime[j] == 0) break;
    	}
        }
        dfs(1,1,32,1);
        out(res);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    
  • 相关阅读:
    Matlab实现bwlabel函数(区域标记)功能
    Matlab实现medfilt2函数功能
    Matlab实现基于频域对二维信号的低通滤波
    Matlab实现基于频域对一维信号利用傅里叶低通滤波平滑
    Matlab实现直方图规定化
    Matlab实现直方图均衡化
    Matlab实现imresize函数功能
    lc279贪心
    lc347 解法
    numpy中的np.mat(1)
  • 原文地址:https://www.cnblogs.com/ivorysi/p/9880884.html
Copyright © 2011-2022 走看看