zoj 2562 More Divisors

来源:互联网 发布:冠新软件版本 编辑:程序博客网 时间:2024/06/14 15:12

求反序数

对于任何正整数x,记约数的个数记做g(x).例如g(1)=1,g(6)=4.
如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数.

有两条性质,没有想明白怎么推出来的 直接百度借用了尴尬

性质一:一个反素数的质因子必然是从2开始连续的质数.
因为最多只需要10个素数构造:2,3,5,7,11,13,17,19,23,29
性质二:p=2^t1*3^t2*5^t3*7^t4…..必然t1>=t2>=t3>=..


dfs ,不是很麻烦,所以不详细解释了

code

#include <iostream>#include <fstream>#include <cstdio>#include <algorithm>#include <cstring>#include <string>#include <string.h>#include <vector>#include <bitset>#include <cmath>#include <queue>#include <stack>#include <set>#include <ctime>#include <map>#include <limits>#define LL long long#define Vi vector<int>#define Si set<int>#define readf freopen("input.txt","r",stdin)#define writef freopen("output.txt","w",stdout)#define FF(i,a) for(int i(0); i < (a); i++)#define FD(i,a) for(int i(a); i >= (1); i--)#define FOR(i,a,b) for(int i(a);i <= (b); i++)#define FOD(i,a,b) for(int i(a);i >= (b); i--)#define PD(a) printf("%d",a)#define SET(a,b) memset(a,b,sizeof(a))#define SD(a) scanf("%d",&(a))#define LN printf("\n")#define PS printf(" ")#define pb push_back#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1const double pi = acos(-1.0);const int maxn = 200001;const int INF = 99999999;const int dx[]={0,1,0,-1};const int dy[]={1,0,-1,0};using namespace std;int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};LL N;LL ans,mcnt;void dfs(LL num,LL cnt,LL k,LL lim){    if(k>14) return;    if(cnt>mcnt){        mcnt=cnt;        ans=num;    }    if(cnt==mcnt && num<ans) ans=num;    LL tmp=num;    FOR(i,1,lim){        if(tmp*prime[k]>N) return ;        tmp*=prime[k];        dfs(tmp,cnt*(i+1),k+1,i);    }}int main(){    while(~scanf("%lld",&N)&&N){        ans=N;        mcnt=0;        dfs(1,1,0,50);        printf("%lld\n",ans);    }    return 0;}