URAL1748. The Most Complex Number
反素数
素数的个数随大小的递增而递减 可以相同
注意各种超啊
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define INF 1e19
#define LL unsigned long long
#define N 32000
int p[N],f[N],g,po[N];
LL maxz,tt,pp[N][],n;
void init()
{
int i,j; for(i = ; i < N ; i++)
if(!f[i])
{
for(j = i+i ; j < N ; j+=i)
f[j] = ;
}
for(i = ; i < N ; i++)
if(!f[i])
p[++g] = i;
for(i = ; i <= g ; i++)
{
pp[p[i]][] = p[i];
for(j = ; ; j++)
{
double ss = (double)pp[p[i]][j-]*p[i];
if(ss>INF) break;
pp[p[i]][j]=ss;
//cout<<ss<<endl; }
po[i] = j-;
}
}
void dfs(LL s,int k,int o,LL sum)
{
int i;
LL ts =s;
if(o>) return ;
if(maxz<sum||(maxz==sum&&tt>s))
{
maxz = sum;
tt = s;
}
for(i = ; i <= min(k,po[o]) ; i++)
{
if(n/s<pp[p[o]][i]) break;
s*=pp[p[o]][i];
dfs(s,i,o+,sum*(LL)(i+));
s = ts;
}
}
int main()
{
int t,i;
init();
cin>>t;
while(t--)
{
cin>>n;
maxz=,tt=;
for(i = ; i < po[] ; i++)
{
LL s = pp[][i];
if(s>n)
{
if(i>maxz)
{
maxz = i;
tt = pp[][i-];
}
break;
}
dfs(s,i,,i+);
}
cout<<tt<<" "<<maxz<<endl;
}
return ;
}
URAL1748. The Most Complex Number的更多相关文章
- LeetCode 537. 复数乘法(Complex Number Multiplication)
537. 复数乘法 537. Complex Number Multiplication 题目描述 Given two strings representing two complex numbers ...
- LC 537. Complex Number Multiplication
Given two strings representing two complex numbers. You need to return a string representing their m ...
- ural 1748 The Most Complex Number 和 丑数
题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ...
- [LeetCode] Complex Number Multiplication 复数相乘
Given two strings representing two complex numbers. You need to return a string representing their m ...
- [Swift]LeetCode537. 复数乘法 | Complex Number Multiplication
Given two strings representing two complex numbers. You need to return a string representing their m ...
- LeetCode Complex Number Multiplication
原题链接在这里:https://leetcode.com/problems/complex-number-multiplication/description/ 题目: Given two strin ...
- 【LeetCode】537. Complex Number Multiplication 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 日期 题目地址:https://leetcode.com/pr ...
- 537. Complex Number Multiplication
题目大意: 给出a, b两个用字符串表示的虚数,求a*b 题目思路: 偷了个懒,Python3的正则表达式匹配了一下,当然acm里肯定是不行的 class Solution: def complexN ...
- URAL 1748. The Most Complex Number(反素数)
题目链接 题意 :给你一个n,让你找出小于等于n的数中因子个数最多的那个数,并且输出因子个数,如果有多个答案,输出数最小的那个 思路 : 官方题解 : (1)此题最容易想到的是穷举,但是肯定超时. ( ...
随机推荐
- 【转载】C++编译出现 error C2664: 不能将参数 2 从“const char [5]”转换为“LPCTSTR”解决办法。
编译程序的时候出现这样的错误,原因是在新建MFC项目的时候,设置字符集Unicode的属性. 解决方法一: 在VC2010的解决方案管理器窗口内,右击你的项目“项目”,然后选“属性”(最后一项),再点 ...
- [工作积累] android 中添加libssl和libcurl
1. libssl https://github.com/guardianproject/openssl-android 然后执行ndk-build 2.libcurl 源代码组织结构, 下面的mak ...
- xp/2003开关3389指令
开启3389: @echo offtitle 开启3389clsrem 开启3389reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ ...
- .NET设计模式(4):建造者模式(Builder Pattern)(转)
概述 在软件系统中,有时候面临着“一个复杂对象”的创建工作,其通常由各个部分的子对象用一定的算法构成:由于需求的变化,这个复杂对象的各个部分经常面临着剧烈的变化,但是将它们组合在一起的算法确相对稳定. ...
- geotools解析SLD中的elsefilter为什么里面的filter无效
原因是在org.geotools.renderer.lite.StreamingRenderer中的process函数: /** * @param rf * @param feature * @par ...
- HDOJ 3183 A Magic Lamp
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- SQLserver分页查询实例
Sqlserver数据库分页查询一直是Sqlserver的短板,闲来无事,想出几种方法,假设有表ARTICLE,字段ID.YEAR...(其他省略),数据53210条(客户真实数据,量不大),分页查询 ...
- MVC模式在游戏开发的应用
原地址: http://www.cocoachina.com/gamedev/2012/1129/5212.html MVC是三个单词的缩写,分别为:模型(Model).视图(View)和控制Cont ...
- 安装wine qq2012
添加软件源:vi /etc/apt/sources.list deb http://http.kali.org/kali kali main non-free contribdeb-src http: ...
- IOS第三方地图-百度地图集成
百度地图官网: http://developer.baidu.com/map/index.php?title=iossdk 照上面吧百度地图sdk集成到工程 然后在pilst文件中加入: 如果地图没有 ...