反素数就是1-x中因子数最多的数中最小的数
首先前15个素数的累和就会爆1e18,然后2的60也会爆1e18
反素数一定由不超过15个素数,指数非严格递减生成,这样就有了例题1的搜索框架
-------------------------------------------------------------------------------------------------------------------------------
例题1:给一个数n,求最小的数x让x的因子数为n
1 //#include<bits/stdc++.h> 2 //#pragma comment(linker, "/STACK:1024000000,1024000000") 3 #include<stdio.h> 4 #include<algorithm> 5 #include<queue> 6 #include<string.h> 7 #include<iostream> 8 #include<math.h> 9 #include<stack> 10 #include<set> 11 #include<map> 12 #include<vector> 13 #include<iomanip> 14 #include<bitset> 15 using namespace std; // 16 17 #define ll long long 18 #define ull unsigned long long 19 #define pb push_back 20 #define FOR(a) for(int i=1;i<=a;i++) 21 #define sqr(a) (a)*(a) 22 #define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)) 23 ll qp(ll a,ll b,ll mod){ 24 ll t=1;while(b){if(b&1)t=t*a%mod;b>>=1;a=a*a%mod;}return t; 25 } 26 struct DOT{int x;int y;}; 27 inline void read(int &x){int k=0;char f=1;char c=getchar();for(;!isdigit(c);c=getchar())if(c=='-')f=-1;for(;isdigit(c);c=getchar())k=k*10+c-'0';x=k*f;} 28 void ex(){puts("No");exit(0);} 29 const int dx[4]={0,0,-1,1}; 30 const int dy[4]={1,-1,0,0}; 31 const int inf=0x3f3f3f3f; 32 const ll Linf=0x3f3f3f3f3f3f3f3fLL; 33 const ll Mod=1e18+7; 34 const double eps=1e-6; 35 const double pi=acos(-1.0); 36 37 38 const int prime[20]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; 39 40 int n; 41 ll ans; 42 43 void dfs(int dep,ll num,int cnt){ 44 if(cnt>n)return; 45 if(cnt==n && ans>num)ans=num; 46 for(int i=1;i<=60;i++){ 47 if(ans/prime[dep] < num)break; 48 49 num*=prime[dep]; 50 51 dfs(dep+1,num,cnt*(i+1)); 52 } 53 } 54 55 int main(){ 56 scanf("%d",&n); 57 ans=9e18; 58 59 dfs(1,1,1); 60 printf("%lld ",ans); 61 }
-------------------------------------------------------------------------------------------------------------------------------
例题2:多组的例题1(x),加上了指数降级约束的版本
1 //#include<bits/stdc++.h> 2 //#pragma comment(linker, "/STACK:1024000000,1024000000") 3 #include<stdio.h> 4 #include<algorithm> 5 #include<queue> 6 #include<string.h> 7 #include<iostream> 8 #include<math.h> 9 #include<stack> 10 #include<set> 11 #include<map> 12 #include<vector> 13 #include<iomanip> 14 #include<bitset> 15 using namespace std; // 16 17 #define ll long long 18 #define ull unsigned long long 19 #define pb push_back 20 #define FOR(a) for(int i=1;i<=a;i++) 21 #define sqr(a) (a)*(a) 22 #define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)) 23 ll qp(ll a,ll b,ll mod){ 24 ll t=1;while(b){if(b&1)t=t*a%mod;b>>=1;a=a*a%mod;}return t; 25 } 26 struct DOT{int x;int y;}; 27 inline void read(int &x){int k=0;char f=1;char c=getchar();for(;!isdigit(c);c=getchar())if(c=='-')f=-1;for(;isdigit(c);c=getchar())k=k*10+c-'0';x=k*f;} 28 void ex(){puts("No");exit(0);} 29 const int dx[4]={0,0,-1,1}; 30 const int dy[4]={1,-1,0,0}; 31 const int inf=0x3f3f3f3f; 32 const ll Linf=0x3f3f3f3f3f3f3f3fLL; 33 const ll Mod=1e18+7; 34 const double eps=1e-6; 35 const double pi=acos(-1.0); 36 37 38 const int prime[20]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; 39 40 ll n; 41 ll ans; 42 int bst_cnt; 43 44 void dfs(int dep,int limit,ll now,int cnt){ 45 if(now>n)return; 46 if(cnt>bst_cnt){ 47 bst_cnt=cnt; 48 ans=now; 49 } 50 if(cnt==bst_cnt && ans>now){ans=now;} 51 for(int i=1;i<=limit;i++){ 52 double cur=(double)now; 53 54 if(n<cur*prime[dep])break; 55 dfs(dep+1,i,now*=prime[dep],cnt*(i+1)); 56 } 57 } 58 59 int main(){ 60 int T; 61 scanf("%d",&T); 62 while(T--){ 63 scanf("%lld",&n); 64 ans=Linf; 65 bst_cnt=0; 66 dfs(1,60,1,1); 67 printf("%lld %d ",ans,bst_cnt); 68 } 69 }