高精度+搜索+质数 BZOJ1225 [HNOI2001] 求正整数
// 高精度+搜索+质数 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] 求正整数的更多相关文章
- bzoj1225 [HNOI2001] 求正整数
1225: [HNOI2001] 求正整数 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 762 Solved: 313[Submit][Statu ...
- BZOJ 1225: [HNOI2001] 求正整数( dfs + 高精度 )
15 < log250000 < 16, 所以不会选超过16个质数, 然后暴力去跑dfs, 高精度计算最后答案.. ------------------------------------ ...
- luogu P1128 [HNOI2001]求正整数 dp 高精度
LINK:求正整数 比较难的高精度. 容易想到贪心不过这个贪心的策略大多都能找到反例. 考虑dp. f[i][j]表示前i个质数此时n的值为j的最小的答案. 利用高精度dp不太现实.就算上FFT也会T ...
- BZOJ 1225: [HNOI2001] 求正整数 高精度+搜索+质数
题意:给定n求,有n个因子的最小正整数. 题解:水题,zcr都会,我就不说什么了. 因数个数球求法应该知道,将m分解质因数,然后发现 a1^p1*a2^p2....an^pn这样一个式子, (1+p1 ...
- 【BZOJ1225】求正整数(数论)
题意:对于任意输入的正整数n,请编程求出具有n个不同因子的最小正整数m. n<=50000 思路:记得以前好像看的是maigo的题解 n即为将m分解为质数幂次的乘积后的次数+1之积 经检验只需要 ...
- 【BZOJ】1225: [HNOI2001] 求正整数
http://www.lydsy.com/JudgeOnline/problem.php?id=1225 题意:给一个数n,求一个最小的有n个约数的正整数.(n<=50000) #include ...
- [HNOI2001]求正整数
题目描述 对于任意输入的正整数n,请编程求出具有n个不同因子的最小正整数m. 例如:n=4,则m=6,因为6有4个不同整数因子1,2,3,6:而且是最小的有4个因子的整数. 输入输出格式 输入格式: ...
- [HNOI2001] 求正整数 - 背包dp,数论
对于任意输入的正整数n,请编程求出具有n个不同因子的最小正整数m. Solution (乍一看很简单却搞了好久?我真是太菜了) 根据因子个数计算公式 若 \(m = \prod p_i^{q_i}\) ...
- P1128 [HNOI2001]求正整数
传送门 rqy是我们的红太阳没有它我们就会死 可以考虑dp,设\(dp[i][j]\)表示只包含前\(j\)个质数的数中,因子个数为\(i\)的数的最小值是多少,那么有转移方程 \[f[i][j]=m ...
随机推荐
- ios(苹果公司的移动操作系统)
iOS是由苹果公司开发的移动操作系统. 苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计给iPhone使用的, 后来陆续套用到iPod touch.iPad以及Appl ...
- Git教程之时光穿梭(3)
我们已经成功地添加并提交了一个readme.txt文件,现在我们继续修改readme.txt文件,改成如下内容:
- spring boot 1.4默认使用 hibernate validator
spring boot 1.4默认使用 hibernate validator 5.2.4 Final实现校验功能.hibernate validator 5.2.4 Final是JSR 349 Be ...
- 10个最佳的PHP图像操作库
Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Python, PHP, OCaml等等诸多编程语言的支 ...
- Mac + IDEA + JRebel破解方法.
[重要提示]---最佳人生 一.只推荐当计算机无法访问互联网时使用本破解文件. 二.如果可以访问互联网,建议直接到JRebel官网注册JRebel会员获取[正版永久免费]使用的授权码.JRebel会员 ...
- sqlsevrer中output的用法
近日,看到代码中有output写法,不知其意,经过一番查找,终于找到了原因,它的作用是将修改影响的结果给输出出来. 比如update语句, 除了修改数据以外, 对于发生更新的列, update语句还可 ...
- C#6.0 VS2015
https://msdn.microsoft.com/en-us/library/hh156499(v=vs.140).aspx This page lists key feature names f ...
- LA 3704 (矩阵快速幂 循环矩阵) Cellular Automaton
将这n个格子看做一个向量,每次操作都是一次线性组合,即vn+1 = Avn,所求答案为Akv0 A是一个n*n的矩阵,比如当n=5,d=1的时候: 不难发现,A是个循环矩阵,也就是将某一行所有元素统一 ...
- UITableViewCell上的按钮点击事件处理
转自: http://www.aichengxu.com/view/42871 UITableViewCell上的按钮点击事件处理,有需要的朋友可以参考下. 今天突然做项目的时候,又遇到处理自定义的 ...
- asp.net实现文件解压和压缩
C#解压RAR压缩文件(--转载--测试通过) using System; using System.Collections.Generic; using System.Text; using Sys ...