codeforces 27E Number With The Given Amount Of Divisors
2 seconds
256 megabytes
standard input
standard output
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output the smallest positive integer with exactly n divisors.
4
6
6
12
题目描述是给你一个n,表示一个数有n个约数,要求你求出这个数最小是多少。
在做着个题目之前,我是做了hdu4542这个题目,然后在大牛的微博上看到了题目推荐才去做的。
这个题目和hdu4542很想,它的代码则是属于hdu4542中的一部分。
解题思路其实是,将一个数m做质因数分解后,我们可以将m写成m=p1^a1*p2^a2*p3^a3...pn^an;
难么m的约数的个数就可以写成是(1+a1)*(1+a2)*(1+a3)...*(1+an);
然后用dfs枚举所有可能的组合打成表记录一下。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn=100000;
const long long inf=(1LL<<60)+1;
int prime[maxn+10];
bool check[maxn+10];
int tot;
int N;
void getprime()
{
tot=0;
memset(check,false,sizeof(check));
for(int i=2;i<=maxn;i++)
{
if(!check[i])
prime[tot++]=i;
for(int j=0;j<tot;j++)
{
if(i*prime[j]>maxn)
break;
check[prime[j]*i]=true;
if(i%prime[j]==0)
break;
}
}
}
long long a[1010];
void dfs(int i,long long x,int n)//这里的三个参数的含义:i表示prime数组中对应素数的标号,x表示的是要求解的答案,n表示的是约数的个数。
{
if(n>1000)
return;
if(x<inf&&(a[n]>x||a[n]==0))
a[n]=x;
for(int j=1;j<=60;j++)
{
if(inf/prime[i]<x)
break;
x*=prime[i];
if(x>=inf)
break;
dfs(i+1,x,n*(j+1));
}
}
void init()
{
memset(a,0,sizeof(a));
dfs(0,1,1);
}
int main()
{
getprime();
init();
while(scanf("%d",&N)!=EOF)
{
printf("%I64d\n",a[N]);
}
return 0;
}
codeforces 27E Number With The Given Amount Of Divisors的更多相关文章
- Codeforces 27E. Number With The Given Amount Of Divisors (暴力)
题目链接:http://codeforces.com/problemset/problem/27/E 暴力 //#pragma comment(linker, "/STACK:1024000 ...
- codeforces 27E . Number With The Given Amount Of Divisors 搜索+数论
题目链接 首先要知道一个性质, 一个数x的因子个数等于 a1^p1 * a2^p2*....an^pn, ai是x质因子, p是质因子的个数. 然后就可以搜了 #include <iostrea ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- E. Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Beta Round #27 E. Number With The Given Amount Of Divisors 含n个约数最小数
http://codeforces.com/problemset/problem/27/E RT,求含n个约数的最小的数 我们设答案p = 2^t1 * 3^t2 * -- * p^tk(其中p是第k ...
- codeforces 27 E. Number With The Given Amount Of Divisors(数论+dfs)
题目链接:http://codeforces.com/contest/27/problem/E 题意:问因数为n个的最小的数是多少. 题解:一般来说问到因数差不多都会想到素因子. 任意一个数x=(p1 ...
- 大家一起做训练 第一场 E Number With The Given Amount Of Divisors
题目来源:CodeForce #27 E 题目意思和题目标题一样,给一个n,求约数的个数恰好为n个的最小的数.保证答案在1018内. Orz,这题训练的时候没写出来. 这道题目分析一下,1018的不大 ...
- 【数学】【CF27E】 Number With The Given Amount Of Divisors
传送门 Description 给定一个正整数\(n\),输出最小的整数,满足这个整数有n个因子 Input 一行一个整数\(n\) Output 一行一个整数,代表答案. Hint \(1~\leq ...
- 数论 CF27E Number With The Given Amount Of Divisors
求因子数一定的最小数(反素数) #include<iostream> #include<string> #include<cmath> #include<cs ...
随机推荐
- jQuery focus、blur事件 添加、删除类名
jQuery.focusblur = function(ele,className){ var focusblurid = $(ele); focusblurid.focus(function(){ ...
- Android 6.0 新特性
首先谈一谈Android 6.0的一些新特性 锁屏下语音搜索 指纹识别 更完整的应用权限管理 Doze电量管理 Now onTap App link 在开发过程中与我们关系最密切的就是"更完 ...
- 简单几句话总结Unicode,UTF-8和UTF-16
概念 先说一说基本的概念,这包括什么是Unicode,什么是UTF-8,什么是UTF-16. Unicode,UTF-8,UTF-16完整的说明请参考Wiki(Unicode,UTF-8,UTF-16 ...
- linux系统下yum 安装mysql的方法
菜鸟一个,记录下yum 安装mysql的方法,给需要的朋友也做个参考吧. 弄了个新vps,想安装最新版的mysql,网上查了相关资料,记录如下: 1.安装查看有没有安装过: yum ...
- poj3237
//Accepted 2280 KB 688 ms /* source:poj3237 time :2015.5.29 by :songt */ /*题解: 树链剖分 基于边权,路径查询最大值 线段树 ...
- TextWatcher 编辑框监听器
TextWatcher tw = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int sta ...
- spring 整合 spring mvc
需要进行 Spring 整合 SpringMVC 吗 ? 还是否需要再加入 Spring 的 IOC 容器 ? 是否需要再 web.xml 文件中配置启动 Spring IOC 容器的 Context ...
- JSP自定义标签
在JSP网页编程中,我们通常不满足于jstl或其他的框架,我们也可以自己写属于自己专用的标签. 在这里介绍一下表格中展示JavaBean的自定义标签的使用 第一步:写一个父标签,用来显示获取数据 新建 ...
- C#中datatable导出excel(三种方法)
方法一:(拷贝直接可以使用,适合大批量资料, 上万笔) Microsoft.Office.Interop.Excel.Application appexcel = new Microsoft.Offi ...
- android4.4以上,快捷实现标题栏透明
方法很简单写一个values-v19的文件夹,当安卓版本大于4.4时便会调用该文件夹下的styles.xml文件 结构如图: styles.xml <resources> <!-- ...