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 ...
随机推荐
- -canOpenURL: failed for URL: "" - error: "(null)" , iOS9 App传输安全 支持http 解决方案
-canOpenURL: failed for URL: "CamCardHDOpenAPI:*" - error: "(null)" This app is ...
- 基于Flask的Web应用部署到SAE上遇到的问题
我的应用底层数据库用的是MySQL,利用Flask-SQLALchemy实现接口操作.我遇到的问题是: 在我把代码部署到SAE上后,当数据向数据库insert的时候总是出现“2006,MySQL ha ...
- JavaScript贷款计算器
今天花了两个小时模仿书上代码用JS制作了JavaScript贷款计算器,时间有些长,但相比以前,自己细心了不少,每天进步一点点,量的积累达到质的飞跃 <!doctype html>< ...
- gradle环境配置、
话不多说,直接上流程. 1.下载 gradle.zip文件,我以为已经为大家准备好了各个版本的下载地址. 链接: http://pan.baidu.com/s/1hqjIVlE 密码: 8ccb 本人 ...
- python2.7安装matplotlib遇到的问题及解决方法
python2.7下import matplotlib报错 第一个报错是:缺少这个pyparsing-2.1.4.win32-py2.7.exe 直接下载安装就行 第二个报错是:缺少cycler 这个 ...
- java基础之 序列化
一.序列化和反序列化的概念 把对象转换为字节序列的过程称为对象的序列化. 把字节序列恢复为对象的过程称为对象的反序列化. 对象的序列化主要有两种用途: 1) 把对象的字节序列永久地保存到硬 ...
- 设置DIV块元素在浏览器页面中垂直居中
任务目标 实践HTML/CSS布局方式 深入了解position等CSS属性 任务描述 实现如 示例图(点击打开) 的效果 灰色元素水平垂直居中,有两个四分之一圆位于其左上角和右下角. 任务注意事项 ...
- 在浏览器地址栏前添加自定义的ico图标
首先,我们需要预先制作一个图标文件,大小为16*16像素.文件扩展名为ico,然后上传到相应目录中. 在HTML源文件“<head></head>”之间添加如下代码: < ...
- Java集合运用技巧
需要唯一吗? 需要:Set 需要制定顺序吗? 需要:TreeSet 不需要:HashSet 但是想要一个和存储一致的顺序(有序):LinkedHashSet 不需要:List 需要频繁增删吗? 需要: ...
- iOS中block的用法 以及和函数用法的区别
ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候 MyBlock(); 带参数的 ...