【codeforces 27 E】【反素数】【给一个数n,求一个最小的正整数,使得它的因子个数为n】
2016-10-29 16:08
519 查看
传送门:http://codeforces.com/problemset/problem/27/E
描述;
E. Number With The Given Amount Of Divisors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Given the number n, find the smallest positive integer which has exactly n divisors.
It is guaranteed that for the givenn the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactly n divisors.
Examples
input
output
input
output
题意:
给一个数n,求一个最小的正整数,使得它的因子个数为n
思路:
与求因子的方法类似,先建立搜索树,以每一个pi为一层建立树型结构,进行搜索,取最小的。
反素数的讲解:点击打开链接
代码:
描述;
E. Number With The Given Amount Of Divisors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Given the number n, find the smallest positive integer which has exactly n divisors.
It is guaranteed that for the givenn the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactly n divisors.
Examples
input
4
output
6
input
6
output
12
题意:
给一个数n,求一个最小的正整数,使得它的因子个数为n
思路:
与求因子的方法类似,先建立搜索树,以每一个pi为一层建立树型结构,进行搜索,取最小的。
反素数的讲解:点击打开链接
代码:
#include <bits/stdc++.h> using namespace std; #define ull unsigned long long const ull inf = ~0ULL; int p[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};//这16个素数乘起来接近于ull最大值 //因为质因数的指数不递减,所以所以指数为1的时候不爆ull的最多16个质数 int n; ull ans; void dfs(int dep, ull tmp, int num){ //深度,当前数的值,因数的个数 if(num > n)return ;//因数多于n回溯 if(num == n && ans > tmp) ans = tmp; for(int i = 1; i <= 63; i++){ //枚举指数 if(tmp > ans / p[dep])break; //满足最小 dfs(dep + 1, tmp *= p[dep], num * (i + 1)); } } int main(){ while(cin>>n){ ans = inf; dfs(0, 1, 1); cout << ans << endl; } return 0; }
相关文章推荐
- 任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0。
- hdu 5428 The Factor 求一个数列的乘积的最小因子的因子数大于2 筛素数
- 任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0。
- 用素数因子分解一个正整数
- 输入一个正整数n,返回一个最小正整数m(m至少是2位数),使得m的各位乘积等于n,例如输入36,输出49,输入100,输出455,对于某个n不存在这样的m,请返回-1。
- 输入一个正整数n,输出一个最小正整数m,使得m的各位乘积等于n
- 给定一个正整数x,找到一个最小的正整数y,使得y的每一位相乘,最后值等于x
- 反素数 模板 求因子的个数为n的最小的数是什么
- 1、判断一个数是否为素数,并求出1-1000中的全部素数(素数即质数,除1和自身以外没有其它因子,最小的质数是2)。
- 【codeforces 721D】【贪心 堆】D. Maxim and Array 【给出n个数,k次机会,每次使得任意一个数字减少或者加上x,使得最后的乘积最小,最后的n个数大小】
- 【codeforces 724D】【贪心】 Dense Subsequence 【一个字符串,按照一定的区间要求从中选出一些字符,使得这串字符的sort后字典序最小】
- 输入一个高精度的正整数n,去掉其中任意s个数字后剩下的数字按原左右次序将组成一个新的正整数。编程对所给的n和s,寻找一种方案使得剩下的数字组成的新数最小。
- SEERC15 求一个正整数n,使得a+n和b+n的LCM值最小
- 陈利人 面试题 对于一个n位正整数a,去掉其中任意k(k<=n)个数字后,剩下的数字按原次序排列可以组成一个新的正整数。设计一个删数算法,使得剩下的数字组成的正整数最小。
- 任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0。
- 反素数 模板 求因子的个数为n的最小的数是什么
- 对于一个n位正整数a,去掉其中任意k(k<=n)个数字后,剩下的数字按原次序排列可以组成一个新的正整数。设计一个删数算法,使得剩下的数字组成的正整数最小。例如,a=13243221,k=5,输出:12
- 第十一周上机任务——项目3:(1)输入一个正整数,判断其是否为一个素数
- 设有n个正整数,将它们联接成一排,组成一个最小的多位整数
- hdu 1164(一个数的素数因子)