More Divisors(反素数)
More Divisors
Time Limit: 2 Seconds Memory Limit: 65536 KB
Everybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is often not very convenient, ten has only four divisors -- 1, 2, 5 and 10. Thus, fractions like 1/3, 1/4 or 1/6 have inconvenient decimal representation. In this sense the notation with base 12, 24, or even 60 would be much more convenient.
The main reason for it is that the number of divisors of these numbers is much greater -- 6, 8 and 12 respectively. A good quiestion is: what is the number not exceeding n that has the greatest possible number of divisors? This is the question you have to answer.
Input:
The input consists of several test cases, each test case contains a integer n (1 <= n <= 1016).
Output:
For each test case, output positive integer number that does not exceed n and has the greatest possible number of divisors in a line. If there are several such numbers, output the smallest one.
Sample Input:
10
20
100
Sample Output:
6
12
60
题解:找小于等于n的因子个数最大的最小整数; 代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
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;
const uLL INF=(uLL)~0;
int prim[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
uLL n,ans;
int nn;
void dfs(int pos,uLL v,int num){
if(num==nn)ans=min(ans,v);
if(num>nn&&v<=n)nn=num,ans=v;
for(int i=1;i<=63;i++){
if(v*prim[pos]>n)break;
dfs(pos+1,v*=prim[pos],num*(i+1));
}
}
int main(){
while(~scanf("%llu",&n)){
nn=0;ans=INF;
dfs(0,1,1);
printf("%llu\n",ans);
}
return 0;
}
More Divisors(反素数)的更多相关文章
- 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 ...
- ZOJ-2562 More Divisors 反素数
题意:给定一个数N,求小于等于N的所有数当中,约数最多的一个数,如果存在多个这样的数,输出其中最大的一个. 分析:反素数定义:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4 ...
- CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)
CodeForces - 27E Number With The Given Amount Of Divisors Submit Status Description Given the number ...
- 【POJ2886】Who Gets the Most Candies?-线段树+反素数
Time Limit: 5000MS Memory Limit: 131072K Case Time Limit: 2000MS Description N children are sitting ...
- Prime & 反素数plus
题意: 求因数个数为n的最小正整数k. n<=10^9输出其唯一分解形式 SOL: 模拟题,一眼看过去有点惊讶...这不是我刚看过的反素数吗... 咦数据怎么这么大,恩搞个高精吧... 于是T了 ...
- BZOJ 1053 & 反素数
题意: 反素数,膜一篇GOD's Blog...http://blog.csdn.net/ACdreamers/article/details/25049767 此文一出,无与争锋... CODE: ...
- Who Gets the Most Candies?(线段树 + 反素数 )
Who Gets the Most Candies? Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%I64d &am ...
- BZOJ 3085: 反质数加强版SAPGAP (反素数搜索)
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3085 题意:求n(<=10^100)之内最大的反素数. 思路: 优化2: i ...
- 【bzoj1053】反素数
[bzoj1053]反素数 题意 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例 ...
随机推荐
- 最近用的到的一些js的常用方法(简单的)
由于新的项目开始了,是使用MVC 5.0 开发的,前端使用了两个主流的框架 UIKIT,Ignite UI(收费) 因为是mvc主要用json来交互,不能避免要对前端脚本进行操作,所以就将能用到的方法 ...
- DEV GridControl 小结(持续添加)
一.属性: 1.Views OptionsBehavior=>Editable:False 列表不可编辑 OptionsSelection=>EnableAppearanceFocuse ...
- 记录一次webbrowser无法加载 activex 遇到的问题
关联配置: win7 x64 Adobe Reader XI activex 安装目录X84 笔者项目运行Any CPU 无论如何也加载不出PDF 刚开始还以为自己封装的控件XWebBrowser的问 ...
- mvc模式jsp+servel+dbutils oracle基本增删改查demo
mvc模式jsp+servel+dbutils oracle基本增删改查demo 下载地址
- Vijos 1083 小白逛公园(线段树)
线段树,每个结点维护区间内的最大值M,和sum,最大前缀和lm,最大后缀和rm. 若要求区间为[a,b],则答案max(此区间M,左儿子M,右儿子M,左儿子rm+右儿子lm). ----------- ...
- Git使用方法记录(一)
记录下git的基本使用方法,这里是以ubuntu14.04为例. 1,使用前的初始设置 git config –global user.name “FirstName LastName” git co ...
- 对程序员的不尊重是中国it产业的悲哀。
电脑刚进入中国时,“程序员”三个字是一份令人尊敬的岗位,那个时候中国互联网人才奇缺.程序员的价格也就水涨船高.小的时候电视里到处播放着电脑培训学院的招生广告.一说到程序员,给我们的印象都是白领,高薪的 ...
- 如何将windows版的vim界面语言(默认为中文)设置成英文
用安装包安装windows版本的vim(下载地址:http://www.vim.org/download.php),vim会自动根据windows的语言设置vim的界面语言.如何将其改为英文呢? 在v ...
- HDU 2815 Mod Tree
不会,先搁着…… http://blog.csdn.net/acm_cxlove/article/details/7832197
- APUE学习之---------------进程
离职了,交接期也有足够的时间了,可以在好好的再看一下APUE,想想上次详细的看还是在两年之前,虽然中间也偶尔会翻出来看看,但是由于工作上交集相对比较少一直没有去细读一下.现在正好是一段空挡期可以好好看 ...