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)此题最容易想到的是穷举,但是肯定超时. ( ...
随机推荐
- Windows键盘快捷键
- Codeforces Round #216 (Div. 2)解题报告
又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<]; ,m2=; ;i ...
- 解决Ubuntu下内存不足---作为Slave的虚拟机
1)在虚拟机上安装了Ubuntu桌面版作为DataNode,由于物理机内存的限制只是分了1G的内存给虚拟机,使用bin/start-all.sh启动了hadoop之后,Slave的资源使用情况如下图所 ...
- POJ 1458
#include <iostream> #include <string> #define MAXN 1000 using namespace std; string s_1; ...
- Android loader 详解
装载器从android3.0开始引进.它使得在activity或fragment中异步加载数据变得简单.装载器具有如下特性: 它们对每个Activity和Fragment都有效. 他们提供了异步加载数 ...
- SqlServer 常用
Sql的函数 newId() 获得guid: getDatatime() 获得当前时间: Row_number() 分页常用的函数. 比top 好用的函数select Row_Number() ov ...
- UVA 10574 - Counting Rectangles 计数
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...
- 搭建turnserver
参考文件: http://blog.csdn.net/kl222/article/details/20145423 为什么要搭建TURN服务器? 因为我们编写的sip客户端再和南瑞的sip服务器进行通 ...
- 在db2中 两个数据库之间的两个表的联合查询
大家好,今天遇到了在db2中 两个数据库之间的两个表的联合查询 我知道oracle中有dblink,可是不知到db2的两个数据库联合查询怎么处理我找了类似于比如两个数据库: db1,db2用户名密码s ...
- 让fdisk输出更准确合理
注意:新版本的fdisk默认输出已经正确合理了,本文只适用于旧版本的fdisk. 1 无option选项参数的输出 [root@localhost ~]# fdisk -l Disk /dev/sda ...