高精度+搜索+质数 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 ...
随机推荐
- MIT算法导论——第二讲.Solving Recurrence
本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...
- Hibernate逍遥游记-第13章 映射实体关联关系-005双向多对多(使用组件类集合\<composite-element>\)
1. <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...
- Go语言的优点(oschina讨论)
Go语言的优点:并发/网络/性能/工具(fmt/pprof/test)/标准库(http/json/log/flags/atomic)/GoogleGo语言垃圾回收器真正致命的缺陷是,会导致整个进程不 ...
- Qt出现警告 Unescaped backslashes are deprecated!解决办法
Fixing Qt Warning: Unescaped backslashes are deprecated! From: http://www.openguru.com/2011/10/fixin ...
- 用matlab训练数字分类的深度神经网络Training a Deep Neural Network for Digit Classification
This example shows how to use Neural Network Toolbox™ to train a deep neural network to classify ima ...
- 在BSP的.bat文件下設置全局變量方法
用于多個產品共用一個BSP的時候,在BSP的.bat文件中設置全局變量,去掉不需要加載的驅動和不同點是很好的方法. 一,舉例:BSP中.bat的一段code: set BSP_SMDK2443=1 s ...
- BootStrap基本样式
文本对齐风格:.text-left:左对齐.text-center:居中对齐.text-right:右对齐.text-justify:两端对齐 取消列表符号:.list-unstyled内联列表:.l ...
- JS兼容性问题(FF与IE)
不同浏览器中js兼容问题大全 1.document.formName.item('itemName')问题 说明: //IE下(两种) document.formName.item("ite ...
- 漫谈 polling 和 Websocket
Http被设计成了一个单向的通信的协议,即客户端发起一个request,然后服务器回应一个response.这让服务器很为恼火:我特么才是老大,我居然不能给小弟发消息... 轮询 老大发火了,小弟们自 ...
- Selenium Tutorial (1) - Starting with Selenium WebDriver
Starting with Selenium WebDriver Selenium WebDriver - Introduction & Features How Selenium WebDr ...