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 ...
随机推荐
- 爬虫:selenium + phantomjs 解决js抓取问题(一)
selenium模块主要用来做测试,模拟键盘.鼠标来操作浏览器. phantomjs 就像一个无界面的浏览器一样. 两个结合能很好的解决js抓取的问题. 测试代码: #coding=utf-8 fro ...
- android 加载中、无网络、无数据、出错 四种状态的代码封装
package com.weavey.loading.lib;import android.content.Context;import android.content.res.TypedArray; ...
- Javascript DOM编程艺术 语法部分
1.变量,可以变化的东西我们称为变量,随着年龄的增大,我们的age不断变大 2.Javascript变量声明用var,可以不声明变量类型.尽量声明为一个字符串字面量. 3.弱类型:要求程序员必须明确的 ...
- win7 安装JDK7和JDK8后,卸载JDK8后出错
这是本人学习Java过程中遇到的一些问题和解决方法,在此记录,方便本人查看,解决他人疑惑. 本人win7 x64旗舰版,同时安装了JDK7和JDK8,卸载了JDK8之后,cmd命令行输入:java - ...
- JS 笔记(一)
1. 页面引入 1) 标签直接引入脚本(推荐): <script type="text/javascript"> 脚本语言 </script> 2) 标签引 ...
- post和get请求
get请求:不安全,参数在url地址中的参数的长度不能大于1024字节 post请求:安全,参数都是凤凰族昂在data里的,参数长度不限
- 通过声明Attribute属性改变不同类的输出效果
ConsoleApplication--控制台应用程序 首先创建基类: using System; using System.Collections.Generic; using System.Lin ...
- .net core 学习笔记(2)-中间件
小项目中有个操作日志的功能,主要是记录用户对修改数据的操作进行记录,记录的内容包括 访问的控制器和方法,以及控制器方法中接收的参数,操作用户,及操作IP等信息,最开始是用ActionFilterAtt ...
- 总结:视频播放的四种实现方案(Native)
一.来自 AVFoundation的 AVPlayer对象 特点: 1. AVPlayer > 优点: 可以自定义UI, 进行控制 > 缺点: ...
- JavaScript onblur 和 onkeyup事件用法
1.onblur表示失去焦点的时候被调用: 2.onkeyup表示键盘每输入完一个字符之后发生.简单来讲,就是键盘上的按键被放开的时候触发. 例子: <!DOCTYPE HTML PUBLIC ...