题目链接:https://vjudge.net/problem/11177

题目大意:

  求小于等于 n 的最大反素数。

分析:

  n <= 10^18,而前20个素数的乘积早超过10^18,因此可手动打素数表,再dfs寻找最大反素数。

代码如下:

 #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std; #define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef set< int > SI;
typedef vector< int > VI;
typedef map< int, int > MII;
typedef vector< LL > VL;
typedef vector< VL > VVL;
const double EPS = 1e-;
const int inf = 1e9 + ;
const LL mod = 1e9 + ;
const int maxN = 5e5 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; int T;
LL n;
PLL ans; int primes[] = {, , , , , , , , , , , , , , , }; // x 表示当前处理到第 x 个质数
// ret为当前选择下的质数乘积
// pcnt 为 1~x-1 个质数中,每个质数选择数量+1的乘积
// limit 表示第x个质数选则的上限
// cnt表示第 x 个质数已经选了多少个
inline void dfs(int x = , LL ret = , LL pcnt = , int limit = inf, int cnt = ) {
if(ret > n || limit < cnt) return;
LL tmp = pcnt * (cnt + );
if(ans.sd < tmp || ans.sd == tmp && ans.ft > ret) ans = MP(ret, tmp); if(n / ret >= primes[x])dfs(x, ret * primes[x], pcnt, limit, cnt + ); // 选 primes[x]
if(cnt) dfs(x + , ret, tmp, cnt, ); // 不选 primes[x]
} int main(){
INIT();
cin >> T;
while(T--) {
cin >> n;
ans = MP(inf, -);
dfs();
cout << ans.ft << " " << ans.sd << endl;
}
return ;
}

URAL 1748 The Most Complex Number的更多相关文章

  1. ural 1748 The Most Complex Number 和 丑数

    题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ...

  2. URAL 1748. The Most Complex Number(反素数)

    题目链接 题意 :给你一个n,让你找出小于等于n的数中因子个数最多的那个数,并且输出因子个数,如果有多个答案,输出数最小的那个 思路 : 官方题解 : (1)此题最容易想到的是穷举,但是肯定超时. ( ...

  3. LeetCode 537. 复数乘法(Complex Number Multiplication)

    537. 复数乘法 537. Complex Number Multiplication 题目描述 Given two strings representing two complex numbers ...

  4. LC 537. Complex Number Multiplication

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  5. URAL 1837. Isenbaev&#39;s Number (map + Dijkstra || BFS)

    1837. Isenbaev's Number Time limit: 0.5 second Memory limit: 64 MB Vladislav Isenbaev is a two-time ...

  6. URAL1748. The Most Complex Number

    1748 反素数 素数的个数随大小的递增而递减 可以相同 注意各种超啊 #include <iostream> #include<cstdio> #include<cst ...

  7. [LeetCode] Complex Number Multiplication 复数相乘

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  8. [Swift]LeetCode537. 复数乘法 | Complex Number Multiplication

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  9. LeetCode Complex Number Multiplication

    原题链接在这里:https://leetcode.com/problems/complex-number-multiplication/description/ 题目: Given two strin ...

随机推荐

  1. 析构中delete this

    查看下面代码如何出错 #include <iostream> using namespace std; class A { public: A() { p = this; } ~A() { ...

  2. VTemplate模板引擎的使用--高级篇

    VTemplate模板引擎的使用--高级篇 在网站中,经常会有某个栏目的数据在多个页面同时使用到.比如新闻网站或电子商务网站的栏目列表,几乎在很多页面都会显示栏目导航.对于这种多个页面同时使用到的“数 ...

  3. Rsync 实现服务器文件的同步——服务端的安装配置

    一.安装rsync 直接使用yum命令进行安装即可. yum -y install rsync 二.配置文件 网上大多教程都说安装是默认没有配置文件的,但是经过我的尝试,yum安装下默认是有配置文件的 ...

  4. qcom_IMS_conference_call小结

    1conference call建立 用QXDM抓qcom log: 1.拨号盘*#*#825364#*#*    ,  进入抓log UI 2.Connectivity-->USB Port ...

  5. 基于MFC的Media Player播放器的制作(3---功能实现)

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 下面我们试试一下,按下退出Button退出播放器的功能: 首先,我们双击退出Button按钮,就会弹出下图的框: 上面的弄好之后我们就实现 ...

  6. 关于原生js中ie的attacheEvent事件用匿名函数改变this指向后,不能用detachEvent删除绑定事件的解决办法?

    博客搬迁,给你带来的不便,敬请谅解! http://www.suanliutudousi.com/2017/11/28/%e5%85%b3%e4%ba%8e%e5%8e%9f%e7%94%9fjs%e ...

  7. Java转型大数据开发全套教程,都在这儿!

    众所周知,很多语言技术已经在长久的历史发展中掩埋,这期间不同的程序员也走出的自己的发展道路. 有的去了解新的发展趋势的语言,了解新的技术,利用自己原先的思维顺利改变自己的title. 比如我自己,也都 ...

  8. linux 下安装chrome的rpm包

    1. 下载chrome的rpm包,假设叫cho. 2.执行命令 rpm -ivh cho 3.报错提示需要lsb>=4.0,执行命令 yum install lsb 等待安装完毕. 4. 重新执 ...

  9. springCloud的使用01-----服务的注册和发现

    1 搭建eureka注册服务器 1.1 创建springboot项目,导入相应的jar包依赖 <project xmlns="http://maven.apache.org/POM/4 ...

  10. arcpy-栅格转其他格式

    import arcpy in_format=arcpy.GetParameterAsText(0) out_format=arcpy.GetParameterAsText(1) out_folder ...