URAL 1748 The Most Complex Number
题目链接:https://vjudge.net/problem/11177
题目大意:
求小于等于 n 的最大反素数。
分析:
代码如下:
#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的更多相关文章
- ural 1748 The Most Complex Number 和 丑数
题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ...
- URAL 1748. The Most Complex Number(反素数)
题目链接 题意 :给你一个n,让你找出小于等于n的数中因子个数最多的那个数,并且输出因子个数,如果有多个答案,输出数最小的那个 思路 : 官方题解 : (1)此题最容易想到的是穷举,但是肯定超时. ( ...
- 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 1837. Isenbaev's Number (map + Dijkstra || BFS)
1837. Isenbaev's Number Time limit: 0.5 second Memory limit: 64 MB Vladislav Isenbaev is a two-time ...
- URAL1748. The Most Complex Number
1748 反素数 素数的个数随大小的递增而递减 可以相同 注意各种超啊 #include <iostream> #include<cstdio> #include<cst ...
- [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 ...
随机推荐
- PAT甲级——A1144 TheMissingNumber【20】
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...
- java 并发——volatile
java 并发--volatile 介绍 维基百科: volatile 是一个类型修饰符(type specifier).volatile 的作用是确保本条指令不会因编译器的优化而省略,且要求每次直接 ...
- docker内的服务无法获取用户真实IP
原文:blog.baohaipeng.top 背景:MySQL数据库和Redis运行在宿主机上(Linux),server运行在docker内,web运行在Nginx内(Nginx运行在docker内 ...
- 用Emacs进行Python开发
用Emacs进行Python开发 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} ...
- Vue 单页应用 的 首屏优化
对于单页应用,要在一个页面上为用户提供产品的所有功能,在这个页面加载的时候,首先要加载大量的静态资源,这个加载时间相对比较长.所以我们需要做一些相应的优化,减少响应时间,尽快把首屏显示出来. 1.压缩 ...
- ASP.NET MVC SignalR 简单聊天推送笔记
介绍:(抄袭于网络) ASP.NET SignalR 是为 ASP.NET 开发人员提供的一个库,可以简化开发人员将实时 Web 功能添加到应用程序的过程.实时 Web 功能是指这样一种功能:当所连接 ...
- mongoose 常用数据库操作 删除
删除 Model.remove(conditions, [callback]) try.js var User = require("./user.js"); function d ...
- java格式化时间 String 转Date Date转String
---恢复内容开始--- 时间格式化 Date类型转换成String: Date date = new Date();SimpleDateFormat sdf = new SimpleDateForm ...
- leetcood学习笔记-20
python字符串与列表的相互转换 学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 str1 = "hi hello world" print(str1.s ...
- Jmeter-【If控制器】-__jexl3函数&__groovy函数
一.使用场景 根据请求返回结果中某一字段的取值判断往下走的流程.例如: 二.__jexl3函数实现 格式:${__jexl3(,)} 三.__groovy函数实现 格式:${__groovy(,)}