CF27E Number With The Given Amount Of Divisors
阿新 • • 發佈:2021-08-21
題目
CF27E Number With The Given Amount Of Divisors
分析
不知道為什麼這種提這麼多。
根據因數和公式,發現質因數個數很少,於是直接搜尋即可。
程式碼
#include<bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x){ x=0;char ch=getchar();bool f=false; while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=f?-x:x; return ; } template <typename T> inline void write(T x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10^48); return ; } const int N=1e5+5,M=1e6+5,MOD=1e9+7; int n,p[100]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,47},a[20]; long long Ans=0x3f3f3f3f3f3f3f3f; double QuickPow(double a,long long b){double res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;} void dfs(int pos,int now){ if(now==1){ double res=1; for(int i=1;i<=pos-1;i++) res=res*QuickPow(p[i],a[i]-1); if(res<=1e18) Ans=min(Ans,(long long)res); return ; } for(int i=now;i>=2;i--) if(now%i==0) a[pos]=i,dfs(pos+1,now/i); return ; } int main(){ read(n); dfs(1,n); write(Ans); return 0; }