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(反素数)的更多相关文章

  1. 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 ...

  2. ZOJ-2562 More Divisors 反素数

    题意:给定一个数N,求小于等于N的所有数当中,约数最多的一个数,如果存在多个这样的数,输出其中最大的一个. 分析:反素数定义:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4 ...

  3. CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)

    CodeForces - 27E Number With The Given Amount Of Divisors Submit Status Description Given the number ...

  4. 【POJ2886】Who Gets the Most Candies?-线段树+反素数

    Time Limit: 5000MS Memory Limit: 131072K Case Time Limit: 2000MS Description N children are sitting ...

  5. Prime & 反素数plus

    题意: 求因数个数为n的最小正整数k. n<=10^9输出其唯一分解形式 SOL: 模拟题,一眼看过去有点惊讶...这不是我刚看过的反素数吗... 咦数据怎么这么大,恩搞个高精吧... 于是T了 ...

  6. BZOJ 1053 & 反素数

    题意: 反素数,膜一篇GOD's Blog...http://blog.csdn.net/ACdreamers/article/details/25049767 此文一出,无与争锋... CODE: ...

  7. Who Gets the Most Candies?(线段树 + 反素数 )

    Who Gets the Most Candies? Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%I64d &am ...

  8. BZOJ 3085: 反质数加强版SAPGAP (反素数搜索)

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3085 题意:求n(<=10^100)之内最大的反素数. 思路: 优化2: i ...

  9. 【bzoj1053】反素数

    [bzoj1053]反素数 题意 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例 ...

随机推荐

  1. VS2015 启用“仅我的代码”

    在调试网站的时候,如果不勾选 [启用"仅我的代码"],会跳出一大堆异常,但是异常不作处理,非常烦人: 解决办法就是在 [调试]->[选项]->[勾选 启用"仅 ...

  2. [Jobdu] 题目1283:第一个只出现一次的字符

    题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出现一次的字符. 输入: 输入有多组数据每一组输入一个字符串. 输出: 输出第一个只出现一次的字 ...

  3. YII框架下实现密码修改

    YII2 实现修改密码功能 主要难点: 1.密码加密 YII2对密码加密生成的结果是不同的,即用相同的初始密码在不同时间得到的加密结果不同,所以我们不能用常用的方法去验证密码是否正确(将密码加密后与数 ...

  4. HTML+CSS笔记 CSS中级 缩写入门

    盒子模型代码简写 回忆盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左. 语法: margin:10px 15p ...

  5. Webx pull service

    1.概述 pull service的功能是将对象置入模板中.被pull service放到模板中的对象,不需要应用程序的干预即可直接使用.如果模板没有用到某个对象,则不会产生创建该对象的开销.看起来, ...

  6. Tomcat 中会话超时的相关配置

      QC同事提到似乎有时Tomcat的会话超时表现有问题,记录一下可能用到的配置. 1)超时时间的设定       tomcat的会话超时可以在多个级别上设置:tomcat实例级别.Web应用级别.s ...

  7. spss

    编辑 SPSS(Statistical Product and Service Solutions),“统计产品与服务解决方案”软件.最初软件全称为“社会科学统计软件包” (SolutionsStat ...

  8. Android平台APK分析工具包androguard的部署使用和原理分析

    原创文章,转载请注明出处,谢谢. Android应用程序分析主要有静态分析和动态分析两种,常见的静态分析工具是Apktool.dex2jar以及jdgui.今天突然主要到Google code上有个叫 ...

  9. 射频识别技术漫谈(19)——Desfire的3次握手认证和段密码生成

    3次握手认证并生成临时的通讯密钥在通讯技术中的应用非常普遍,Mifare Desfire也使用了这种成熟的认证加密方法.Desfire在卡片数据传输前使用DES或3DES进行3次握手认证,认证成功一方 ...

  10. docpad建站记录

    记一下用docpad建站的过程作为备忘.不定时更新 why docpad wordpress对我来说太过于臃肿,我就想要个代码干净的小站来写东西.想要个markdown为基础的静态站. 比较流行的St ...