CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)
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
4
6
6
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(反素数)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- js中if的简写方法
http://transitions1020.com/# 太帅! <script type="text/javascript"> 如果你想写 if (!false) { ...
- ASP.NET之电子商务系统开发-3(订单)
一.前言 继上次的购物车,这是第三篇.记录一下订单功能.这功能做的时候,走过弯路,很是烧脑,因为思路没理顺,数据库设计的也不怎么好,做到一半才发现有问题,接着把数据库重新设计好,理清思路后,终于完成了 ...
- 两个textarea 同时变化高度
<html><head><script type="text/javascript" src="/jquery/jquery.js" ...
- C# - 通过自定义注解反射生成SQL语句[转]
转自http://blog.163.com/jong_cai/blog/static/87028045200902033553581/ -------------------------------- ...
- [LeetCode]题解(python):115-Distinct Subsequences
题目来源: https://leetcode.com/problems/distinct-subsequences/ 题意分析: 给定字符串S和T,判断S中可以组成多少个T,T是S的子串. 题目思路: ...
- 正则语法笔记-regular expression note
参考文档:python正则表达式 正则表达式定义:正则是一门高度专业编程语言,内嵌在其他语言(python re模块)中使用.正则表达式包含元字符(metacharacter)列表,列表如下: . ^ ...
- HTML+CSS笔记 CSS入门续集
继承 CSS的某些样式是具有继承性的,那么什么是继承呢?继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代(标签). 语法: p{color:red;} <p> ...
- arm中的ldr指令
label .equ 0x53000000 ldr r0, label : 将0x53000000地址处的值放入r0中 ldr r0, =label : 将0x53000000付值给r0.
- angularjs学习总结(快速预览版)
对html标签的增强 -> 指令 指令的本质是什么 声明的方式调用相应的脚本,实现一些操作,声明的所在的dom就是脚本的执行上下文? 自定义标签 -- 标签指令自定义属性 -- 属性指令特定格式 ...
- 基于Visual C++2013拆解世界五百强面试题--题18-程序结果分析2-终结篇
第二部分程序结果分析,分析流程还是写入代码注释中 分析下面程序的输出: #include <stdio.h> int main() { char *a = "hello" ...