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

------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
 
using namespace std;
 
const int maxn = 50009;
const int n = 16;
const int p[n] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
 
int N, ans[n], g[n], ansn;
double cur = 1e30;
 
void dfs(int x, int lim, double res, int cnt) {
if(res > cur) return;
if(cnt == N) {
if(res < cur) {
ansn = x;
for(int i = 0; i < x; i++) ans[i] = g[i];
cur = res;
}
} else {
if(x == n) return;
for(int i = 0; i <= lim; i++) if(cnt * (i + 1) <= N) {
g[x] = i;
dfs(x + 1, i, res + i * log(p[x]), cnt * (i + 1));
}
}
}
 
struct Int {
static const int base = 10000;
static const int width = 4;
static const int maxn = 1000;
int s[maxn], n;
Int() {
n = 0;
memset(s, 0, sizeof s);
}
Int(int x) {
n = 0;
for(; x; x /= base) s[n++] = x % base;
}
Int operator = (const Int &o) {
n = o.n;
memcpy(s, o.s, sizeof(int) * n);
return *this;
}
Int operator * (const Int &o) const {
Int ret; ret.n = n + o.n - 1;
for(int i = 0; i < n; i++)
for(int j = 0; j < o.n; j++) 
ret.s[i + j] += s[i] * o.s[j];
for(int i = 0; i < ret.n; i++) if(ret.s[i] >= base) {
ret.s[i + 1] += ret.s[i] / base;
ret.s[i] %= base;
}
for(int &i = ret.n; ret.s[i]; i++) if(ret.s[i] >= base) {
ret.s[i + 1] += ret.s[i] / base;
ret.s[i] %= base;
}
return ret;
}
void write() {
int buf[width], c;
for(int i = n; i--; ) {
c = 0;
for(int t = s[i]; t; t /= 10) buf[c++] = t % 10;
if(i != n - 1)
for(int j = width - c; j--; ) putchar('0');
while(c--) putchar(buf[c] + '0');
}
puts("");
}
};
 
int main() {
scanf("%d", &N);
dfs(0, N - 1, 0, 1);
Int res = 1;
for(int i = 0; i < ansn; i++) {
Int _p = p[i];
for(int j = 0; j < ans[i]; j++)
res = res * _p;
}
res.write();
return 0;
}

------------------------------------------------------------------------------

1225: [HNOI2001] 求正整数

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 576  Solved: 232
[Submit][Status][Discuss]

Description

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

Input

n(1≤n≤50000)

Output

m

Sample Input

4

Sample Output

6

HINT

Source

Dp

BZOJ 1225: [HNOI2001] 求正整数( dfs + 高精度 )的更多相关文章

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

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

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

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

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

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

  4. bzoj1225 [HNOI2001] 求正整数

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

  5. 高精度+搜索+质数 BZOJ1225 [HNOI2001] 求正整数

    // 高精度+搜索+质数 BZOJ1225 [HNOI2001] 求正整数 // 思路: // http://blog.csdn.net/huzecong/article/details/847868 ...

  6. [HNOI2001]求正整数

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

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

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

  8. P1128 [HNOI2001]求正整数

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

  9. 求正整数n所有可能的和式的组合(如;4=1+1+1+1、1+1+2、1+3、2+1+1、2+2

    作者:张小二 nyoj90 ,可以使用递归的方式直接计算个数,也可以通过把满足的个数求出来计数,因为在juLy博客上看到整数划分,所以重写了这个代码,就是列出所m的可能性,提交后正确.acmer的入门 ...

随机推荐

  1. ora-01653: unable to extend table sys.aud$ by 8192 in tablespac system[转载]

    在用sqlplus user/password@truth登录数据库时报如下错误:ORA-00604: error occurred at recursive SQL level 1ORA-01653 ...

  2. java selenium webdriver实战 页面元素定位

    自动化测试实施过程中,测试程序中常用的页面操作有三个步骤 1.定位网页上的页面元素,并存储到一个变量中 2.对变量中存储的页面元素进行操作,单击,下拉或者输入文字等 3.设定页面元素的操作值,比如,选 ...

  3. eclipse及Java常用问题及解决办法汇总

    junit-test 我觉得这点比idea好用,可以直接选中要测试的方法名,右击run as即可 http://www.cnblogs.com/brolanda/p/4532779.html 打开您的 ...

  4. Windows Azure 上 Linux VM 中的交换空间 – 第 2 部分

    本文章由 Azure CAT 团队的 Piyush Ranjan (MSFT) 撰写. 在前一篇文章 Windows Azure 上Linux VM 中的交换空间第 1 部分中,我介绍了在默认情况下, ...

  5. data pump(数据泵)

    先给出oracle给出的一个定义: “Oracle Data Pump technology enables very high-speed movement of data and metadata ...

  6. 那些年我们写过的三重循环----CodeForces 295B Greg and Graph 重温Floyd算法

    Greg and Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  7. 用DBMS_ADVISOR.SQLACCESS_ADVISOR创建SQL Access Advisor访问优化建议

    使用OEM方式来创建SQL Access Advisor访问优化建议,已经是四五年的事了,下面就来写写怎样使用DBMS_ADVISOR.SQLACCESS_ADVISOR来创建SQL Access A ...

  8. contextServlet

    一:读取配置文件中的参数信息 1.新建servlet文件ContextServlet1,代码为: import java.io.IOException; import java.util.Enumer ...

  9. 联想S720/S720i通刷刷机包 Vibe V1.0

    ROM介绍 基于官方最新S116底包制作,保证足够的稳定性. 增加VIBE元素,看起来更加大气.美观. 首次增加VIBE元素,720i执行起来无压力,720可能会有点卡.自行酌情刷入. 有bug请文明 ...

  10. 自己的第一个android应用(天气)

    主界面代码 package com.example.weather; import android.os.Bundle; import android.app.Activity; import and ...