码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ2562

时间:2019-08-04 10:42:22      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:put   eof   ret   getch   namespace   etc   scanf   ++i   ios   

ZOJ2562
https://vjudge.net/problem/11781/origin
<=n的且因子数最多的那个数
做法:同因子数取最小,dfs更新答案

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#define inf ~0
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(unsigned long long i=a;i<=b;++i)

using namespace std;
unsigned long long n,ans,now;
unsigned long long prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
void in(unsigned long long &x){
    unsigned long long y=1;char c=getchar();x=0;
    while(c<0||c>9){if(c==-)y=-1;c=getchar();}
    while(c<=9&&c>=0){ x=(x<<1)+(x<<3)+c-0;c=getchar();}
    x*=y;
}
void o(unsigned long long x){
    if(x<0){p(-);x=-x;}
    if(x>9)o(x/10);
    p(x%10+0);
}

void dfs(unsigned long long depth,unsigned long long num,unsigned long long cnt,unsigned long long up){
    if(num>=now&&cnt<=ans)
        return;
    if(ans<cnt){
        ans=cnt;
        now=num;
    }
    if(ans==cnt&&now>num)
        now=num;
    For(i,1,up){
        if(num*prime[depth]>n) return;
        dfs(depth+1,num*=prime[depth],cnt*(i+1),i);
    }
}

int main(){
    while(scanf("%llu",&n)!=EOF){
        ans=0;
        now=0;
        dfs(0,1,1,64);
        o(now);
        p(\n);
    }
    return 0;
}

 

ZOJ2562

标签:put   eof   ret   getch   namespace   etc   scanf   ++i   ios   

原文地址:https://www.cnblogs.com/war1111/p/11297213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!