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 ...
随机推荐
- 【jQuery】百分比自适应屏幕轮播图特效
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android WebView useragent
今天介绍一下Android WebView UserAgent, User-Agent(简称UA)是HTTP请求头部用来标识客户端信息的字符串, 包括操作系统, 浏览器等信息.为了建立手机客户端的信息 ...
- C++与Java的语法区别
C++与Java的语法区别 首先,两个大的不同是主函数和怎样编译的不同,接下来是许多小的区别. main 函数C++//自由浮动的函数int main( int argc, char* argv[]) ...
- Python学习基本
刚开始学习是看了这个网站: 廖雪峰的官方网站 http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac92707 ...
- Qt之C语言有符号数与无符号数运算
以32位的stm32f4为例: 1. uint32_t t_int_k = 239773, t_int_km1 = 4294859707; 则t_int_k - t_int_km1 > 0; ...
- UIView点击事件。弹出视图,背景虚化。
@interface CountryViewController //背景 @property (strong, nonatomic) UIView *BackView; end //设置背景虚化 - ...
- JS 4 新特性:混合属性(mixins)
Ext JS4的新特征1:混合属性(mixins) 组合是Extjs4的新特性,可用于实现多继承的情况.该属性会以同步方式加载类文件,并实例化该类(译者推理其内部使用Ext.create方法).直接上 ...
- B2C电子商务基础系统架构解析(转载)
系统的开发与演化,前台严格follow消费者的购买流程,后台则盯牢订单流转,牢牢抓住这两条主线,才能高屋建瓴的看清B2C的逻辑链和数据流,更深刻的规划功能模块,从而更有效支撑实际业务的流转. 前台 前 ...
- Android数据库 — — —查询数据
package com.example.datebasetest; import android.content.ContentValues;import android.database.Curso ...
- JS总结 节点
nodeName 获取节点名称 元素节点:返回标记名称 属性节点:返回属性名称 文本节点:返回文本#text nodeTyle 获取节点类型 元素节点:返回1 属性节点:返回2 文本节点:返回3 n ...