题目链接:https://www.nowcoder.com/acm/contest/144/J

标题:J、Heritage of skywalkert

| 时间限制:1 秒 | 内存限制:256M

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 ≤ 107, 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 106.

输出描述:

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.

示例 1

输入

2

2 1 2 3

5 3 4 8

输出

Case #1: 68516050958

Case #2: 5751374352923604426

题意概括:

按照给出的函数打出 N 个数, 求其中两个数的最小公倍数的最大值。

官方题解:

由于数据看上去像是随机⽣生成的,只需要选出前 100 大的数平方暴力即可。 随机两个正整数互质的概率为 6/(π^2) = 0.608...

解题思路:

nth_element()选出前100大的数,暴力前 100 大的数取最大的最小公倍数。

AC code:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#define INF 0x3f3f3f3f
#define ll unsigned long long
using namespace std; const int MAXN = 1e7+; ll num[MAXN];
unsigned int N, A, B, C;
unsigned int x, y, z; ll gcd(ll x, ll y)
{
return y==?x:gcd(y, x%y);
} bool cmp(ll x, ll y)
{
return x>y;
} unsigned tang()
{
unsigned t;
x ^= x<<;
x ^= x>>;
x ^= x<<;
t = x;
x = y;
y = z;
z = t^x^y;
return z;
} int main()
{
int T_case;
scanf("%d", &T_case);
int cnt = ;
while(T_case--)
{ scanf("%u%u%u%u", &N, &A, &B, &C);
x = A, y = B, z = C;
for(int i = ; i < N; i++)
{
num[i] = tang();
}
unsigned int k = min(100u, N);
nth_element(num, num+k, num+N, cmp);
ll res = ;
for(int i = ; i < k; i++)
for(int j = i+; j < k; j++)
{
res = max(res, num[i]*num[j]/gcd(num[i],num[j]));
}
printf("Case #%d: %llu\n", ++cnt, res);
}
return ;
}

(第六场)Heritage of skywalkert 【玄学】的更多相关文章

  1. 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard

    山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...

  2. noi.ac 第五场第六场

    t1应该比较水所以我都没看 感觉从思路上来说都不难(比牛客网这可简单多了吧) 第五场 t2: 比较套路的dp f[i]表示考虑前i个数,第i个满足f[i]=i的最大个数 i能从j转移需要满足 j< ...

  3. NOI.AC NOIP模拟赛 第六场 游记

    NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...

  4. Heritage of skywalkert

    Heritage of skywalkert skywalkert, the new legend of Beihang University ACM-ICPC Team, retired this ...

  5. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

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

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

  7. 牛客网暑期ACM多校训练营(第六场) J Heritage of skywalkert(数论, eth_element)

    链接: https://www.nowcoder.com/acm/contest/144/J 题意: 给定一个函数, 求它n次结果中任意两次的lcm最大值 分析: 首先要看出这个函数并没有什么含义, ...

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

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

  9. 2016多校第六场题解(hdu5793&hdu5794&hdu5795&hdu5800&hdu5802)

    这场就做出一道题,怎么会有窝这么辣鸡的人呢? 1001 A Boring Question(hdu 5793) 很复杂的公式,打表找的规律,最后是m^0+m^1+...+m^n,题解直接是(m^(n+ ...

随机推荐

  1. GitHub+Hexo+gulp搭建博客网站

    一.前期准备 1.注册GitHub账号. 不做说明 2.创建仓库 创建一个新的仓库来放置我们的文件. 3.下载安装Node.js https://nodejs.org/en/   两个版本,选择右边那 ...

  2. filter 静态资源

    package com.itheima.web.filter; import java.io.IOException; import javax.servlet.Filter; import java ...

  3. cloudemanager安装时出现failed to receive heartbeat from agent问题解决方法(图文详解)

    不多说,直接上干货! 安装cdh5到最后报如下错误: 安装失败,无法接受agent发出的检测信号. 确保主机名称正确 确保端口7182可在cloudera manager server上访问(检查防火 ...

  4. 关于jqgrid的一些使用

    1.jqgrid如何切换中英文 在做电力监控系统的时候,根据项目的需要涉及到中英文的切换,一直纠结了好久没有好的办法,虽然我知道可以手动更改引入的js文件就可以更改中英文,但是动态的一直没有办法更改, ...

  5. Visual Studio 创建封装自己的代码段(C#)

    https://www.cnblogs.com/awaTangjay/p/6644952.html 1.打开vs2012--工具--代码段管理器 2.进入代码管理器之后,语言选择Visual C#,然 ...

  6. Coursera 机器学习 第9章(上) Anomaly Detection 学习笔记

    9 Anomaly Detection9.1 Density Estimation9.1.1 Problem Motivation异常检测(Density Estimation)是机器学习常见的应用, ...

  7. core核心模块

    5. core核心模块 核心模块会通过compiler模块提供的调用compiler的功能, 将用户的输入转为VM直接的输入 编译模块用来编译, 而核心模块用来执行 在core.h文件中 // 不需要 ...

  8. ACdream 1099——瑶瑶的第K大——————【快排舍半,输入外挂】

    瑶瑶的第K大 Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status ...

  9. nyoj 1208——水题系列——————【dp】

    水题系列 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述     给你一个有向图,每条边都有一定的权值,现在让你从图中的任意一点出发,每次走的边的权值必须必上一次的权 ...

  10. 拼凑的宿主-host

    开发两年之久,竟然不知道host这个词是什么意思.前些天有幸遇到了,就跟别人请教了.今天理絮一下.总比不知道强吧. 白话来说宿主就是一些框架运行机制运行时需要依赖的平台. 例如web开发常用的IIS, ...