UVA_1575
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[]){;}
UVA_1575的更多相关文章
随机推荐
- 报错:ERROR! The server quit without updating PID file (/usr/local/var/mysql/chenyuntekiMacBook-Air.local.pid).
在Mac上通过brew install mysql 安装了完mysql 执行mysql.server start 报错:ERROR! The server quit without updating ...
- 启用adb wifi无线调试功能(无需root)
1 工具 电脑.手机 2 前提 电脑和手机出于同一网段 3 步骤 以管理员方式打开cmd,运行 adb tcpip 5555(执行tcpip调试模式) adb connect 192.168. ...
- mysql复制过滤参数说明
参考文档: http://www.ywnds.com/?p=6945 https://stackoverflow.com/questions/23191160/whats-the-difference ...
- margin与padding如何进行区分
margin与padding如何进行区分,这是很多学html人的困扰,其实说白了padding 就是内容与边框的空隙.而margin则是模块与模块的空隙.[3]
- js判断是安卓 还是 ios webview?
通过判断浏览器的userAgent,用正则来判断是否是ios和Android客户端.代码如下: <script type="text/javascript"> var ...
- 2018最新Python小白入门教程,30天学会Python
随着Python的技术的流行,Python在为人们带来工作与生活上带来了很多的便捷,因为Python简单,学起来快,也是不少新手程序员入门的首选语言.作为一名Python爱好者,我也想跟大家分享分享我 ...
- JAVA学习笔记16——线程生命周期
当线程被创建并启动以后,它既不是一启动就进入了执行状态,也不是一直处于执行状态,在线程的生命周期中,它要经过新建(New).就绪(Runnable).运行(Running).阻塞(Blocking)和 ...
- Queueingconsumer 找不到
springboot从1.5.9升级到2.0.0,queueingconsumer报错没有这个类,改为使用 DefaultConsumer
- boostrap标签
字体: <lead>:加强显示 <strong><b>:字体加粗 <i><em>:斜体字 .text-muted:提示,使用浅灰色(#999 ...
- 什么是 C 和 C ++ 标准库?
简要介绍编写C/C ++应用程序的领域,标准库的作用以及它是如何在各种操作系统中实现的. 我已经接触C++一段时间了,一开始就让我感到疑惑的是其内部结构:我所使用的内核函数和类从何而来? 谁发明了它们 ...