http://codeforces.com/problemset/problem/27/E
假设P(i)代表某个素数a(i)代表这个素数的幂
那么任何一个数都可以分解成 ( P(1)^a(1) )*( P(2)^a(2) )*( P(3)^a(3) )*.............*( P(k)^a(k) )
而且这个数的约数的数量为 (a(1)+1)*(a(2)+1)*(a(3)+1)*.............*(a(k)+1)
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<map> #include<set> #include<vector> #include<stack> #include<queue> #include<algorithm> #include<cmath> #define LL long long #define ULL unsigned long long using namespace std; const int INF=0x3f3f3f3f; const long long LINF=ceil(1e18); int p[11]={1,2,3,5,7,11,13,17,19,23,29}; long long ans; void dfs(int x,int n,long long M) {//cout<<x<<" "<<n<<" "<<M<<endl; if(n==1) {ans=min(ans,M);return ;} long long k=p[x]; for(int l=1;l<n&&k<LINF;++l,k=k*p[x]) if(n%(l+1)==0) {//cout<<x<<" "<<l<<" "<<M*k<<endl; if(M*k>LINF||M*k<=0) break; dfs(x+1,n/(l+1),M*k); } } int main() { //freopen("data.in","r",stdin); int n; while(cin>>n) { ans=LINF; dfs(1,n,1); cout<<ans<<endl; } return 0; }