CodeForces - 27E

Submit Status

Description

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.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000).

Output

Output the smallest positive integer with exactly n divisors.

Sample Input

Input
4
Output
6
Input
6
Output
12
题解:反素数:

今天要我要讲的是反素数,在ACM中也算是常见的考点,那么对于搞ACM的同学来说,很有必要搞清楚它,所以接下

来我会很详细地讲解。

在讲解反素数之前,我们先来看反素数的概念。

反素数的定义:对于任何正整数,其约数个数记为,例如,如果某个正整数满足:对任意的正整

,都有,那么称为反素数。

从反素数的定义中可以看出两个性质:

(1)一个反素数的所有质因子必然是从2开始的连续若干个质数,因为反素数是保证约数个数为的这个数尽量小

(2)同样的道理,如果,那么必有

在ACM竞赛中,最常见的问题如下:

(1)给定一个数,求一个最小的正整数,使得的约数个数为

(2)求出中约数个数最多的这个数

从上面的性质中可以看出,我们要求最小的,它的约数个数为,那么可以利用搜索来解。

以前我们求一个数的所有因子也是用搜索,比如,以每一个为树的一层建立搜索树,深度为

为例进行说明,建树如下:

可以看出从根节点到每一个叶子结点这条路径上的所有数字乘起来都是12的约数,所以12有6个约数。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define T_T while(T--)
#define P_ printf(" ")
typedef unsigned long long uLL;
int prim[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};//定义16个是因为这16个想乘正好超ull
int n;
uLL ans;
void dfs(int pos,uLL v,int num){//注意v的类型。。。
if(num==n&&ans>v)ans=v;
//if(num>n)return;
for(int i=1;i<=63;i++){
if(num*(i+1)>n||v*prim[pos]>ans)break;//这里在于优化,要不要均可以;
dfs(pos+1,v*=prim[pos],num*(i+1));//保证小的素数必须成才能保证值的小。。。
}
}
int main(){
while(~scanf("%d",&n)){
// printf("%llu\n",(uLL)2*3*5*7*11*13*17*19*23*29*31*37*41*43*47*53);
ans=(uLL)~0;
dfs(0,1,1);
printf("%llu\n",ans);
}
return 0;
}

  

CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)的更多相关文章

  1. codeforces 27E 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 ...

  2. 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 ...

  3. Codeforces 27E. Number With The Given Amount Of Divisors (暴力)

    题目链接:http://codeforces.com/problemset/problem/27/E 暴力 //#pragma comment(linker, "/STACK:1024000 ...

  4. codeforces 27E . Number With The Given Amount Of Divisors 搜索+数论

    题目链接 首先要知道一个性质, 一个数x的因子个数等于 a1^p1 * a2^p2*....an^pn, ai是x质因子, p是质因子的个数. 然后就可以搜了 #include <iostrea ...

  5. 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 ...

  6. 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 ...

  7. codeforces 27 E. Number With The Given Amount Of Divisors(数论+dfs)

    题目链接:http://codeforces.com/contest/27/problem/E 题意:问因数为n个的最小的数是多少. 题解:一般来说问到因数差不多都会想到素因子. 任意一个数x=(p1 ...

  8. 大家一起做训练 第一场 E Number With The Given Amount Of Divisors

    题目来源:CodeForce #27 E 题目意思和题目标题一样,给一个n,求约数的个数恰好为n个的最小的数.保证答案在1018内. Orz,这题训练的时候没写出来. 这道题目分析一下,1018的不大 ...

  9. 【数学】【CF27E】 Number With The Given Amount Of Divisors

    传送门 Description 给定一个正整数\(n\),输出最小的整数,满足这个整数有n个因子 Input 一行一个整数\(n\) Output 一行一个整数,代表答案. Hint \(1~\leq ...

  10. 数论 CF27E Number With The Given Amount Of Divisors

    求因子数一定的最小数(反素数) #include<iostream> #include<string> #include<cmath> #include<cs ...

随机推荐

  1. ASP.NET产生随机验证码

    效果图:(Flowing) 1.项目中新建用于存储(位图)图片文件夹 图解: 2.前台可以添加一ASP.NET控件或其他任意用来展示图片标签等(如下) <div> <asp:Imag ...

  2. CSS 文章段落样式

    #adiv p { text-align: left; text-indent: 2em; line-height:25px; font-family:微软雅黑; font-size:medium; ...

  3. HTML+CSS笔记 CSS中级 缩写入门

    盒子模型代码简写 回忆盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左. 语法: margin:10px 15p ...

  4. 为什么要用on()而不直接使用click

    为什么要用on()而不直接使用clickhttp://stackoverflow.com/questions/10082031/why-use-jquery-on-instead-of-clickht ...

  5. Node Node

    http://www.nodejs.org/ http://outofmemory.cn/code-snippet/1403/node-javascript-classic-introduction- ...

  6. 射频识别技术漫谈(9)——动物标签HDX

    半双工(HDX,Half Duplex)技术是ISO11784/11785中规定的另一种标签与读写器之间的通讯方式.读写器先打开射频场对标签充电以激活标签,然后关闭磁场,标签在读写器磁场关闭的情况下向 ...

  7. CreateFile,ReadFile等API详解(或者说MSDN的翻译)

    一.*****CreateFile***** 这个函数可以创建或打开一个对象的句柄,凭借此句柄就可以控制这些对象:控制台对象.通信资源对象.目录对象(只能打开).磁盘设备对象.文件对象.邮槽对象.管道 ...

  8. perl5 第四章 列表和数组变量

    第四章 列表和数组变量 by flamephoenix 一.列表二.数组--列表的存贮  1.数组的存取  2.字符串中的方括号和变量替换   3.列表范围  4.数组的输出  5.列表/数组的长度  ...

  9. Oracle DBA常用的系统表

    1.2 DBA常用的表1.2.1  dba_开头    dba_users数据库用户信息    dba_segments  表段信息    dba_extents    数据区信息    dba_ob ...

  10. Android Manifest.xml 结构详解

    关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activities ...