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. window 7 改变窗口颜色

    对于刚刚重新安装的window7系统的盆友来说,不能改变窗口的颜色,和别人的window7窗口颜色和样子不一样和不好玩,那么我教大家,如何更改窗口颜色. 首先,重装的系统用软件激活之后,肯定还没还得急 ...

  2. UVa455 Periodic Strings

    #include <stdio.h>#include <string.h> int main(){    int T, k, len;    char str[81], *p, ...

  3. Problem F: Exponentiation

    Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...

  4. php内核一 一次请求与结束

    php开始 到 结束 有两个阶段 请求开始之间的初始化阶段 请求之后的结束处理阶段 开始阶段: 模块初始化 模块激活 模块初始化:    在整个SAPI生命周期内,只执行一次(apache服务器启动的 ...

  5. 当x含有偶数个1,返回1,否则为0。

    题目描述: /* Return 1 when x contains an even number of 1s;0 otherwise. Assume W=32 */ int even_ones(uns ...

  6. html常用标签有哪些?

    html看似复杂,其实常用的标签并不多,这里总共介绍一些html的常用标签 文字处理: ①标题:<h1> to <h6> ②段落:<p>文字段落</p> ...

  7. 城通网盘,千军万马,千脑网盘,119g网盘哪个适合做网赚?

    转载请注明文章来自 [ofiicexie] 网盘网赚已经流行了有一段时间了,国内流行的几个网盘有城通,千军万马,千脑,119g,今天小编写以此文来比较分析一下这几个网盘的优缺点. 这里,我特意做了个这 ...

  8. 菜农群课笔记之ICP与ISP----20110412(整理版)

    耗时一上午时间对HOT大叔昨晚的群课内容进行温故并整理,现将其上传,若想看直播可到下面链接处下载:http://bbs.21ic.com/icview-229746-1-1.html        成 ...

  9. DropDownList控件学习

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  10. C语言 HTTP上传文件-利用libcurl库上传文件

    原文  http://justwinit.cn/post/7626/ 通常情况下,一般很少使用C语言来直接上传文件,但是遇到使用C语言编程实现文件上传时,该怎么做呢? 借助开源的libcurl库,我们 ...