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中this指向问题
1.在全局范围内使用this的时候 它指向的是全局对象 this Window {top: Window, window: Window, location: Location, external: ...
- 用jersey + spring 实现rest服务及单元测试
jersey提供了强大的rest功能,可以通过简洁的标注和编码实现业务的需求,架构会透明的把你的pojo对象转化为客户端可以接受的json/xml文件模式,当然也可以用它做一些基于ajax的表单提交和 ...
- URAL 1297 Palindrome 后缀数组
D - Palindrome Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- UVa1584 Circular Sequence
#include <stdio.h>#include <string.h> int less(char* str, size_t len, size_t p, size_t q ...
- Problem A: A + B
Problem A: A + BTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 17 Solved: 10[Submit][Status][Web Boar ...
- 采用translate实现垂直水平居中
今天分享一个利用css3新特性实现垂直水平居中的方法. 通过对元素进行绝对定位再配合transform中的translate实现. 代码如下: html <div id="conten ...
- 无法在web服务器上启动调试,此项目在使用一个被配置为使用特定IP地址的网站。请在项目URL中指定计算机名称。
解决方案:IIS服务器管理-default web site 绑定-选择使用的IP-编辑-IP地址:全部未匹配
- VC++ win32 多线程 一边画圆一边画矩形
// WinThreadTest.cpp : Defines the entry point for the application. // #include "stdafx.h" ...
- phome_ecms_news 数据表字段解释(新闻系统模型-主表)
http://www.phome.net/doc/manual/extend/html/dbdoc/index.html 字段名 类型 解释 附加说明 id int(11) 信息ID classi ...
- 怪兽z主机 驱动集
这里给买家朋友送上我们主机的驱动包. 1.主板驱动. 访问密码 f334 http://yunpan.cn/QNTGxehcnLBW5 2.AMD显卡催化剂 amd catalyst(没装的话,无法 ...