https://vjudge.net/problem/UVA-1575

枚举答案(k)、、对k质因数分解,质数的指数为cnt[i],若n==A(tot_cnt,tot_cnt) / A(cnt[i]>1),则该ans=k

 #include <cstring>
#include <cstdio> #define LL long long
inline void read(LL &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const int N(1e6+);
LL n,m,k,cnt[N],num,tmp;
inline LL check(LL x)
{
num=tmp=; memset(cnt,,sizeof(cnt));
for(LL i=; i<=x; ++i)
{
if(x%i==)
{
cnt[++num]++;
for(x/=i; x%i==; )
x/=i,cnt[num]++;
}
}
for(LL i=; i<=num; ++i) tmp+=cnt[i];
LL tot=;
for(LL i=; i<=tmp; ++i) tot*=i;
for(LL i=; i<=num; ++i)
if(cnt[i]>) for(LL j=; j<=cnt[i]; ++j) tot/=j;
return tot;
}
int Presist()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
read(n);
for(k=; k<N; ++k)
if(check(k)==n) break;
printf("%d\n",k);
return ;
} int Aptal=Presist();
int main(int argc,char*argv[]){;}

20分。

搜索、记录当前的方案数,合成的k,指数质数上限,要使用的质数,质数个数

从最小的质数开始枚举,可以发现,方案数与质数的指数和有关,

假设前i-1个种质数用了k个,有cnt种方案,第i种质数选a个,

那么前i种质数的方案就有cnt*c[k+a][a]

要求k最小,则小的质数指数越小越好、

 #include <cstdio>

 typedef unsigned long long LL;
int p[]={,,,,,,,,,,,,,,,,,,,};
LL ans,n,c[][]; void DFS(LL k,LL cnt,int lim,int num,int tot)
{
if(k>ans) return ;
if(cnt==n) { ans=k; return ; }
if(num>=||cnt>n) return ;
LL tmp=;
for(int i=; i<=lim; ++i)
{
tmp*=p[num];
if(k>ans/tmp) return ;
DFS(k*tmp,cnt*c[tot+i][i],i,num+,tot+i);
}
} int Presist()
{
c[][]=;
for(int i=; i<; ++i)
{
c[i][]=;
for(int j=; j<=i; ++j)
c[i][j]=c[i-][j-]+c[i-][j];
}
for(;~scanf("%lld",&n); )
{
if(n==)
{ printf("1 2\n");continue; }
ans=(LL)<<;
DFS(,,,,);
printf("%lld %lld\n",n,ans);
}
return ;
} int Aptal=Presist();
int main(int argc,char*argv[]){;}

最新文章

  1. Oracle视图时间戳转为Date
  2. php的数据循环 之li的3个类判断
  3. 关于16年2月14日以后上传AppStore出现:Missing iOS Distribution signing identity for...的问题
  4. 【leetcode】 Letter Combinations of a Phone Number(middle)
  5. 浅谈 switch和if
  6. CCF考前注意几点
  7. 正则表达式(BREs,EREs,PREs)差异比较
  8. Struts2 技术全总结 (正在更新)
  9. sqlQuery.list()方法返回类型
  10. APMServ中的 Apache无法启动…
  11. SegmentFault错误汇总
  12. C语言程序设计第二次作业——顺序结构
  13. CSS3 transform-style 属性
  14. maven依赖查找方法
  15. CLR via C#--------CLR的执行模式
  16. SysUtils.CompareText的注释
  17. 局域网下ARP欺骗、嗅探,以及DNS欺骗
  18. 【Linux】CentOs中yum与rpm区别
  19. 牛客国庆集训派对Day3 I Metropolis
  20. 二叉搜索树BST(Binary Search Tree)

热门文章

  1. Selct 大全
  2. ACM_蛇形矩阵
  3. 笔试题的各种trick
  4. JS获取到时间转换成字符串类型
  5. Integer / BigInteger / BigDecimal 方法
  6. redis学习-sds数据类型
  7. Matlab2014的下载和安装激活过程
  8. [转帖]关于flask-login中各种API使用实例
  9. C++(extern关键字的理解和作用深入)
  10. Hive扩展功能(二)--HWI接口