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)此题最容易想到的是穷举,但是肯定超时. ( ...
随机推荐
- [unroll(num)] for(int i;i<num;i++)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb509602(v=vs.85).aspx Unroll the loop unti ...
- PowerDesigner(九)-模型文档编辑器(生成项目文档)(转)
模型文档编辑器 PowerDesigner的模型文档(Model Report)是基于模型的,面向项目的概览文档,提供了灵活,丰富的模型文档编辑界面,实现了设计,修改和输出模型文档的全过程. 模型文 ...
- 贴代码—CF230 DIV1 B
题目在此: http://codeforces.com/contest/392/problem/B 一直理解错了一句话,以为是用最小的move求最小的花费, 读错题目的有木有!!! 不懂汉诺塔的原理有 ...
- Yahoo, Steve blog
Performance Research Domain Sharding revisited A Software Developer's Guide to HTTP How the Browser ...
- 2013年优秀jQuery插件
今天为大家推荐的是2013年的第一期,在这期里面十个jQuery插件涵盖了响应式的网格布局插件.图片放大插件.表单元素中自定义select插件,google 地图插件.文件拖放上传插件.tooltip ...
- YARN的 AM与RM通信,申请资源分配过程
AppMaster向RM请求资源 MRAppMaster :serviceinit // service to allocate containers from RM (if non-uber) or ...
- 7 天玩转 ASP.NET MVC - 第 1 天
0. 前言 正如标题「7 天玩儿转 ASP.NET MVC」所言,这是个系列文章,所以将会向大家陆续推出 7 篇.设想一下,一天一篇,你将从一个愉快的周一开始阅读,然后在周末成为一个 ASP.NET ...
- POJ 1845 Sumdiv (求某个数的所有正因子的和)
题意: 求A^B的所有正因子的和,最后模9901的结果. 思路: 若对一个数n进行素数分解,n=p1^a1*p2^a2*p3^a3*...*pk^ak那么n的所有正因子之和sum=(1+p1+...+ ...
- Activity学习(二)——生命周期
一.什么是Activity? 简单的说:Activity就是布满整个窗口或者悬浮于其他窗口上的交互界面.在一个应用程序中通常由多个Activity构成,都会在Manifest.xml中指定一个主的Ac ...
- Android Activity 阻止软键盘自动弹出
在AndroidManifest.xml里面 选择那个acitivity, 把他的window soft input mode设置成stateHidden和 adjustUnspecified < ...