链接:https://www.nowcoder.com/acm/contest/144/J
来源:牛客网

skywalkert, the new legend of Beihang University ACM-ICPC Team, retired this year leaving a group of newbies again.

Rumor has it that he left a heritage when he left, and only the one who has at least 0.1% IQ(Intelligence Quotient) of his can obtain it.

To prove you have at least 0.1% IQ of skywalkert, you have to solve the following problem:

Given n positive integers, for all (i, j) where 1 ≤ i, j ≤ n and i ≠ j, output the maximum value among . means the Lowest Common Multiple.

输入描述:

The input starts with one line containing exactly one integer t which is the number of test cases. (1 ≤ t ≤ 50)

For each test case, the first line contains four integers n, A, B, C. (2 ≤ n ≤ 10

7

, A, B, C are randomly selected in unsigned 32 bits integer range)
The n integers are obtained by calling the following function n times, the i-th result of which is ai, and we ensure all ai > 0. Please notice that for each test case x, y and z should be reset before being called.
No more than 5 cases have n greater than 2 x 10

6

.

输出描述:

For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the maximum lcm.

输入例子:
2
2 1 2 3
5 3 4 8
输出例子:
Case #1: 68516050958
Case #2: 5751374352923604426

-->

示例1

输入

复制

2
2 1 2 3
5 3 4 8

输出

复制

Case #1: 68516050958
Case #2: 5751374352923604426 分析:由于数据看上去像是随机⽣成的,只需要选出前 100 ⼤的数平⽅暴⼒即可。 随机两个正整数互质的概率为 6/π。
比赛的时候想到应该是枚举前面最大的多少项,但是因为不知道怎么快速计算前面多少项没有试一发了!!
结束后补题知道了nth_element求数组中最大的前多少项
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef unsigned long long ll;
const ll maxn = 1e7+10;
const ll mod = 998244353;
unsigned x, y, z, a[maxn];
ll n;
unsigned gcd( unsigned a, unsigned b ) {
if( a == 0 ) {
return b;
} else if( b == 0 ) {
return a;
} else {
return gcd( b, a%b );
}
}
unsigned rnd() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll T, t = 1;
scanf("%llu",&T);
while( T -- ) {
scanf("%llu%u%u%u",&n,&x,&y,&z);
for( ll i = 0; i < n; i ++ ) {
a[i] = rnd();
}
ll m = min( (ll)n, (ll)100 );
nth_element( a, a+n-m, a+n );
ll ans = 0;
for( ll i = n-m; i < n; i ++ ) {
for( ll j = i+1; j < n; j ++ ) {
ans = max( ans, (ll)a[i]*a[j]/gcd(a[i],a[j]) );
}
}
printf("Case #%llu: %llu\n", t++, ans);
}
return 0;
}

  

牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)的更多相关文章

  1. 牛客2018多校第六场 J Heritage of skywalkert - nth_element

    传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...

  2. 2019 牛客多校第六场 J Upgrading Technology

    题目链接:https://ac.nowcoder.com/acm/contest/886/J 题目大意 略. 分析 见代码. 代码如下 #include <bits/stdc++.h> u ...

  3. 牛客多校第六场 J Upgrading Technology dp

    题意: 有n个技能,一开始都是0级,第i个技能从j-1级升到j级,花费$c_{i,j}$,但是花费不一定是正的 所有的技能升到j级时,奖励$d_j$但是奖励也不一定是正的 题解: 用sum[i][j] ...

  4. 牛客多校第3场 J 思维+树状数组+二分

    牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...

  5. 牛客多校第五场 J:Plan

    链接:https://www.nowcoder.com/acm/contest/143/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  6. 牛客多校第六场-H-Pair

    链接:https://ac.nowcoder.com/acm/contest/887/H来源:牛客网 题目描述 Given three integers A, B, C. Count the numb ...

  7. 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板

    链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...

  8. 同构图+思维构造——牛客多校第六场E

    考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...

  9. 牛客第六场 J.Heritage of skywalkert(On求前k大)

    题目传送门:https://www.nowcoder.com/acm/contest/144/J 题意:给一个function,构造n个数,求出其中任意两个的lcm的最大值. 分析:要求最大的lcm, ...

随机推荐

  1. java流压缩图片

    整理文档,搜刮出一个Java做图片压缩的代码,稍微整理精简一下做下分享.首先,要压缩的图片格式不能说动态图片,你可以使用bmp.png.gif等,至于压缩质量,可以通过BufferedImage来指定 ...

  2. OV SSL证书有哪些功能?网站安装OV SSL证书的好处

    OV SSL证书英文名称为Organization Validation SSL Certificate,申请OV SSL证书需要审核申请者对域名是否拥有控制权,同时审核申请者是否为一个合法登记.真实 ...

  3. kali Metasploit 连接 Postgresql 默认密码

    使用 metasploit 时, 1. 启动 postgresql service postgresql start 2. 自行测试 postgresql 是否安装成功 根据需要,自行 修改 post ...

  4. Java基础:数组Array转成List的几种方法

    在编写Java程序中,经常要用的一个转换就是数组和List对象之间的互转. 最简单的方法就是遍历 数组,然后将数组元素依次添加进list中. 此方法略,虽然方法很简单,但总感觉这样的方法有点笨 第二种 ...

  5. python第二课--分支结构与循环结构

    if语句---分支结构 在Python中,要构造分支结构可以使用if.elif和else关键字.所谓关键字就是有特殊含义的单词,像if和else就是专门用于构造分支结构的关键字,很显然你不能够使用它作 ...

  6. zabbix自发现item监控

    在zabbix监控中,我们可以通过自带item的可以和自定义key进行监控,但是当所需要的监控项不确定,比如key会根据时间进行变化时,这时候我们就不能把item的key定义死,要通过自发现这个高级功 ...

  7. print,cat打印格式及字符串引号格式,去掉字符串空格 in R

    print 函数的打印格式: ##no quote print out > x <- letters[1:5] > print(x,quote=F,);print(x,quote=T ...

  8. 前端小知识-css3

    一.实现图片倒影 如图: css属性 .style{ -webkit-box-reflect:below 0 linear-gradient(transparent,white 50% ,white) ...

  9. Spring源码剖析1:初探Spring IOC核心流程

    本文大致地介绍了IOC容器的初始化过程,只列出了比较重要的过程和代码,可以从中看出IOC容器执行的大致流程. 接下来的文章会更加深入剖析Bean容器如何解析xml,注册和初始化bean,以及如何获取b ...

  10. 跟我学SpringCloud | 第十五篇:微服务利剑之APM平台(一)Skywalking

    目录 SpringCloud系列教程 | 第十五篇:微服务利剑之APM平台(一)Skywalking 1. Skywalking概述 2. Skywalking主要功能 3. Skywalking主要 ...