UVA 1575 Factors
https://vjudge.net/problem/UVA-1575
题意:
令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式。
例 10=2*5=5*2,所以f(10)=2
给出n,求最小的k
搜索
从最小的质数开始枚举选几个
假设前i-1个种质数用了k个,有sum种方案,第i种质数选a个,
那么前i种质数的方案就有sum*C[k+a][a]
可以理解原来有k个位置,又加了a个位置,有a个数可以放在任意位置
所以前i种的每一种方案都变成C[k+a][a]种
枚举每个质数选几个时,如果上一个质数选了k个,那么这一个质数最多选k个
假设这个质数选了k+1个,那么显然上一个质数选k+1个,这个选k个更优
注意整数类型上限
#include<cstdio>
#include<iostream>
using namespace std;
typedef unsigned long long LL;
int p[]={,,,,,,,,,,,,,,,,,,,,};
LL ans,n;
LL C[][];
void solve(int num,int lim,LL tot,LL now,int last)
{
if(now>ans) return;
if(tot==n) { ans=now; return ; }
if(tot>n || num>) return;
LL t=;
for(int i=;i<=lim;i++)
{
t*=p[num];
if(now>=ans/t) return;
solve(num+,i,tot*C[last+i][i],now*t,last+i);
}
}
int main()
{
C[][]=;
for(int i=;i<;i++)
{
C[i][]=;
for(int j=;j<=i;j++)
C[i][j]=C[i-][j-]+C[i-][j];
} while(scanf("%lld",&n)!=EOF)
{
if(n==)
{
printf("1 2\n");
continue;
}
ans=(LL)<<;
solve(,,,,);
printf("%lld %lld\n",n,ans);
}
}
UVA 1575 Factors的更多相关文章
- UVA 160 - Factors and Factorials
Factors and Factorials The factorial of a number N (written N!) is defined as the product of all t ...
- 紫书 习题 10-25 UVa 1575 (有重复元素的全排列+暴搜)
我一开始以为有什么很牛逼的方法来做,然后一直没有思路 后来看了https://blog.csdn.net/zju2016/article/details/78562932的博客 竟然是暴搜?????? ...
- UVA 10699 Count the factors 题解
Time limit 3000 ms OS Linux Write a program, that computes the number of different prime factors in ...
- uva 129 krypton factors ——yhx
Krypton Factor You have been employed by the organisers of a Super Krypton Factor Contest in which ...
- UVa 884 - Factorial Factors
题目:输出n!中素数因数的个数. 分析:数论.这里使用欧拉筛法计算素数,在计算过程中求解就可以. 传统筛法是利用每一个素数,筛掉自己的整数倍: 欧拉筛法是利用当前计算出的全部素数,乘以当前数字筛数: ...
- UVa 11621 - Small Factors
称号:发现没有比给定数量少n的.只要2,3一个因素的数字组成. 分析:数论.贪婪,分而治之. 用两个三分球,分别代表乘法2,和繁殖3队列,队列产生的数字,原来{1}. 然后.每取两个指针相应元素*2和 ...
- UVa 10299 - Relatives
题目大意:Euler's Totient的应用. 几乎和UVa 10179 - Irreducable Basic Fractions一样,于是偷了个懒,直接用10179题的代码,结果WA了,感觉一样 ...
- UVA - 136 Ugly Numbers (有关set使用的一道题)
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
随机推荐
- 附加题程序找bug
private: void Resize(int sz){ ){ return; } if(maxSize != sz){ T *arr = new T[sz]; if(arr == NULL){ r ...
- linux +redis 安装 +mongo 安装
Linux 下redis安装 本教程使用的最新文档版本为 2.8.17,下载并安装: $ wget http://download.redis.io/releases/redis-2.8.17.tar ...
- Alpha-end
前言 失心疯病源10 团队代码管理github 个人感悟 肝不动了,肝不动了.明天如果见不到我,不要太想我. 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 熬夜肝代码 代码签入git ...
- C语言之goto浅析
1. 读代码时遇了的疑惑点: static int do_bind(const char *host, int port, int protocol, int *family) { int fd; ...
- JAVA之路(一)
距离做下复习JAVA并学好JAVA的决定已经过去一周了,我买了慕课网的JAVA入门视频,在图书馆借了三本关于JAVA的书——两本是JAVA入门经典,一本是JAVA WEB开发宝典.我的计划是短时间内复 ...
- 第7章 监听器Listener
Listener概述 Listener的使用 使用Listener需要实现相应的Listener接口. public class SessionListenerTest implements Http ...
- ZOJ 2060 A-Fibonacci Again
https://vjudge.net/contest/67836#problem/A There are another kind of Fibonacci numbers: F(0) = 7, F( ...
- [CB] 中国超算前100 (联想40 曙光40 浪潮12 国防科大4 华为2 国家并行工程中心2 )
转帖 地址: https://www.cnbeta.com/articles/tech/779633.htm 榜单的前三名和去年相比没有任何变化,依然分别是部署在国家超级计算无锡中心的“神威·太湖之光 ...
- CSS中可以和不可以继承的属性【转】
一.无继承性的属性 1.display:规定元素应该生成的框的类型 2.文本属性: vertical-align:垂直文本对齐 text-decoration:规定添加到文本的装饰 text-shad ...
- py27使用redis
1.安装redis pip install redis 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/