// 高精度+搜索+质数 BZOJ1225 [HNOI2001] 求正整数
// 思路:
// http://blog.csdn.net/huzecong/article/details/8478689
// M=p1^(t1)*p2^(t2)*p3^(t3)....
// N=(t1+1)*(t2+1)*(t3+1)*(t4+1)...
// 所以t最大到16,就可以暴力搜索了 #include <bits/stdc++.h>
using namespace std;
#define LL long long
const double inf = 123456789012345.0;
const LL MOD =100000000LL;
const int N =1e5+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre(){freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int n;
const int M=;
const int p[]= {, , , , , , , , , , , , , , , };
double Log[];
class bignum {
public:
LL num[N];
int tot;
bignum() {}
bignum(LL x) {
clear();
while (x) num[tot++] = x % MOD, x /= MOD;
}
void clear(){
tot = ;
for (int i = ; i < N; ++i) num[i] = 0LL;
}
void operator *= (const int &x){
for (int i = ; i < tot; ++i) num[i] *= x;
for (int i = ; i < tot; ++i)
if (num[i] >= MOD) {
num[i + ] += num[i] / MOD;
num[i] %= MOD;
}
while (num[tot]) {
if (num[tot] >= MOD) {
num[tot + ] += num[tot] / MOD;
num[tot] %= MOD;
}
++tot;
}
}
void print() {
printf("%lld", num[tot - ]);
for (int i = tot - ; i >= ; --i)
printf("%08lld", num[i]);
}
}ans(); int t[],ct[];
double mn;
int cnt; void dfs(int d,int x,int m,double tem){
if(tem>mn) return;
if(x==){
if(tem<mn){
mn=tem,cnt=d-;
for(int i=;i<d;i++) t[i]=ct[i];
}
}
for(int i=;i*i<=x&&i<=m;i++){
if(!(x%i)){
if(i!=){
ct[d]=i;
dfs(d+,x/i,i,tem+(double)Log[d]*(i-));
}
if(x/i<=m&&x/i!=i){
ct[d]=x/i;
dfs(d+,i,x/i,tem+(double)Log[d]*(x/i-));
}
}
}
} int main(){
scanf("%d",&n);
for(int i=;i<=;i++) Log[i]=(double)log(p[i]);
mn=inf;
cnt=;
dfs(,n,n,0.0);
for(int i=;i<=cnt;i++){
for(int j=t[i]-;j>;j--){
ans*=p[i];
}
}
ans.print();
return ;
}

高精度+搜索+质数 BZOJ1225 [HNOI2001] 求正整数的更多相关文章

  1. bzoj1225 [HNOI2001] 求正整数

    1225: [HNOI2001] 求正整数 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 762  Solved: 313[Submit][Statu ...

  2. BZOJ 1225: [HNOI2001] 求正整数( dfs + 高精度 )

    15 < log250000 < 16, 所以不会选超过16个质数, 然后暴力去跑dfs, 高精度计算最后答案.. ------------------------------------ ...

  3. luogu P1128 [HNOI2001]求正整数 dp 高精度

    LINK:求正整数 比较难的高精度. 容易想到贪心不过这个贪心的策略大多都能找到反例. 考虑dp. f[i][j]表示前i个质数此时n的值为j的最小的答案. 利用高精度dp不太现实.就算上FFT也会T ...

  4. BZOJ 1225: [HNOI2001] 求正整数 高精度+搜索+质数

    题意:给定n求,有n个因子的最小正整数. 题解:水题,zcr都会,我就不说什么了. 因数个数球求法应该知道,将m分解质因数,然后发现 a1^p1*a2^p2....an^pn这样一个式子, (1+p1 ...

  5. 【BZOJ1225】求正整数(数论)

    题意:对于任意输入的正整数n,请编程求出具有n个不同因子的最小正整数m. n<=50000 思路:记得以前好像看的是maigo的题解 n即为将m分解为质数幂次的乘积后的次数+1之积 经检验只需要 ...

  6. 【BZOJ】1225: [HNOI2001] 求正整数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1225 题意:给一个数n,求一个最小的有n个约数的正整数.(n<=50000) #include ...

  7. [HNOI2001]求正整数

    题目描述 对于任意输入的正整数n,请编程求出具有n个不同因子的最小正整数m. 例如:n=4,则m=6,因为6有4个不同整数因子1,2,3,6:而且是最小的有4个因子的整数. 输入输出格式 输入格式: ...

  8. [HNOI2001] 求正整数 - 背包dp,数论

    对于任意输入的正整数n,请编程求出具有n个不同因子的最小正整数m. Solution (乍一看很简单却搞了好久?我真是太菜了) 根据因子个数计算公式 若 \(m = \prod p_i^{q_i}\) ...

  9. P1128 [HNOI2001]求正整数

    传送门 rqy是我们的红太阳没有它我们就会死 可以考虑dp,设\(dp[i][j]\)表示只包含前\(j\)个质数的数中,因子个数为\(i\)的数的最小值是多少,那么有转移方程 \[f[i][j]=m ...

随机推荐

  1. HTML5+开发移动app教程3-mui开发示例

    下面就开始一个简答的例子,以及mui相关内容 mui 官网:http://dcloudio.github.io/mui/ 说明:http://dev.dcloud.net.cn/mui/ui/inde ...

  2. MVC5中Model层开发数据注解

    ASP.NET MVC5中Model层开发,使用的数据注解有三个作用: 数据映射(把Model层的类用EntityFramework映射成对应的表) 数据验证(在服务器端和客户端验证数据的有效性) 数 ...

  3. linux自动启动shell和init概述(fedora use systemmd now!!!)

    linux运行级别  linux启动之后会在一个级别运行,下面列出了这些运行级别: 0 系统停止 1 单用户系统,不需要登陆 2 多用户系统但不支持NFS,命令行模式登陆 3 完整多用户模式,命令行模 ...

  4. BZOJ 2004 Bus 公交线路(矩阵)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2004 题意:小Z所在的城市有N个公交车站,排列在一条长(N-1)km的直线上,从左到右依 ...

  5. 【POJ】3134 Power Calculus

    1. 题目描述给定一个正整数$n$,求经过多少次乘法或除法运算可以从$x$得到$x^n$?中间结果也是可以复用的. 2. 基本思路实际结果其实非常小,肯定不会超过20.因此,可以采用IDA*算法.注意 ...

  6. [HDOJ3974]Assign the task(建树胡搞)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 出现在窝bin的线段树专题里…第一时间想的是记录入度找出根节点,然后标记深度转换到线段树中.但是 ...

  7. c#模拟百度电击器方案

    核心提示: 我 们都知道百度对于用户体验很重视,如果一个关键词的某个搜索结果,点击量会很对的话,则百度会认为这个结果是用户所喜欢的结果,然后这个网站自然会在百度 得到一个很好的排名. 网络上也出现了百 ...

  8. Building Xcode iOS projects and creating *.ipa file from the command line

    For our development process of iOS applications, we are using Jenkins set up on the Mac Mini Server, ...

  9. BootStrap图标

  10. SQL2008 R2 主从数据库同步设置

    一.准备工作: 主数据库服务器: OS:Windows Server 2008 R2    DB: SQL Server 2008 R2 Hostname : CXMasterDB IP: 192.1 ...