反素数

反素数

更详细的博客: https://blog.csdn.net/acdreamers/article/details/25049767

1> .  问题一 : 求最小的 X 使其约数个数为 n

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<bitset>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define eps (1e-8)
#define MAX 0x3f3f3f3f
#define u_max 1844674407370955161
#define l_max 9223372036854775807
#define i_max 2147483647
#define re register
#define pushup() tree[rt]=tree[rt<<1]+tree[rt<<1|1]
#define nth(k,n) nth_element(a,a+k,a+n);  // 将 第K大的放在k位
#define ko() for(int i=2;i<=n;i++) s=(s+k)%i // 约瑟夫
using namespace std;

inline int read(){
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' & c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

typedef unsigned long long ll;
const double pi = atan(1.)*4.;
const int M=1e3+5;
const int N=1e6+5;
int n;
int a[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
ll ans=u_max*10;
void dfs(int d,int m,ll cut,int num){
   // printf("YES\n");
    if(d>=16||num>n) return ;
    if(num==n&&ans>cut) ans=cut;
    for(int i=1;i<=m;i++){
        if((ans/a[d]<cut)||(num*(i+1)>n)) break;
        cut*=a[d];
        dfs(d+1,i,cut,num*(i+1));
    }
    return ;
}
int main(){
    scanf("%d",&n);
    dfs(0,63,1,1);
    printf("%llu\n",ans);
    return 0;
}

2>. 问题二:51nod 最复杂的数(1 - n 里面约数个数最多的且最小的数)

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<bitset>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define eps (1e-8)
#define MAX 0x3f3f3f3f
#define u_max 1844674407370955161
#define l_max 9223372036854775807
#define i_max 2147483647
#define re register
#define pushup() tree[rt]=tree[rt<<1]+tree[rt<<1|1]
#define nth(k,n) nth_element(a,a+k,a+n);  // 将 第K大的放在k位
#define ko() for(int i=2;i<=n;i++) s=(s+k)%i // 约瑟夫
using namespace std;

inline int read(){
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' & c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

typedef unsigned long long ll;
const double pi = atan(1.)*4.;
const int M=1e3+5;
const int N=1e6+5;
ll n,ans,sum;
int a[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};

void dfs(int d,int m,ll cut,ll num){
    if(d>=16||cut>n) return ;
    if(num>sum){
        sum=num;
        ans=cut;
    }
    if(num==sum&&cut<ans)
        ans=cut;

    for(int i=1;i<=m;i++){
        if(n/a[d]<cut) break;
        dfs(d+1,i,cut*=a[d],num*(i+1));
    }
    return ;
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%llu",&n);
        sum=0;
        ans=l_max*10;
        dfs(0,63,1,1);
        printf("%llu %llu\n",ans,sum);
    }
    return 0;
}

 

相关文章:

  • 2021-06-29
  • 2021-11-17
  • 2021-10-28
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-06
  • 2021-09-19
  • 2021-08-31
  • 2021-11-11
相关资源
相似解决方案