Heritage of skywalkert

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.

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

-->

 

输入

2
2 1 2 3
5 3 4 8

输出

Case #1: 68516050958
Case #2: 5751374352923604426

题意:n个数求任意两个数的最大的最小公倍数。
暴力模拟了一些数据发现答案的那两个数总是前15大的数,意思就是只有前15大的数才可能组合出答案。
于是用优先队列维护前15大的数,要注意最好尽量减少pop的操作,以免超时。
#include<bits/stdc++.h>
using namespace std;
unsigned int x,y,z;
unsigned int f()
{
unsigned int t;
x^=x<<;
x^=x>>;
x^=x<<;
t=x;
x=y;
y=z;
z=t^x^y;
return z;
} priority_queue<unsigned long long,vector<unsigned long long>,greater<unsigned long long> >team; unsigned long long gcd(unsigned long long a,unsigned long long b)
{
if(a%b==)return b;
return gcd(b,a%b);
} int tot=;
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d %u %u %u",&n,&x,&y,&z); for(int i=; i<=n; i++)
{
unsigned long long now=f(); if(team.size()>=&&team.top()>=now)continue;
team.push(now);
if(team.size()>)team.pop();
} unsigned long long now[];
unsigned long long ans=;
int c1=;
while(!team.empty())
{
now[c1++]=team.top();
team.pop();
} for(int i=; i<c1; i++)
for(int j=; j<c1; j++)
if(i!=j)ans=max(ans,now[i]/gcd(now[i],now[j])*now[j]); printf("Case #%d: %llu\n",tot++,ans);
}
return ;
}

Heritage of skywalkert的更多相关文章

  1. (第六场)Heritage of skywalkert 【玄学】

    题目链接:https://www.nowcoder.com/acm/contest/144/J 标题:J.Heritage of skywalkert | 时间限制:1 秒 | 内存限制:256M s ...

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

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

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

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

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

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

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

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

  6. 随机生成数组函数+nth-element函数

    这几天做了几道随机生成数组的题,且需要用nth-elemeng函数,并且都是北航出的多校题…… 首先我们先贴一下随机生成数组函数的代码: unsigned x = A, y = B, z = C; u ...

  7. R自动数据收集第一章概述——《List of World Heritage in Danger》

      导包     library(stringr) library(XML) library(maps) heritage_parsed <- htmlParse("http://en ...

  8. 洛谷P1827 美国血统 American Heritage

    P1827 美国血统 American Heritage 54通过 90提交 题目提供者JOHNKRAM 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 农夫约翰非 ...

  9. NOIopenjudge 407:Heritage

    总时间限制:  5000ms 内存限制:  65536kB 描述 Your rich uncle died recently, and the heritage needs to be divided ...

随机推荐

  1. NBUT 1115 Cirno's Trick (水)

    题意: 给出多个double数,去掉其最小的和最大的,再对余下的求均值. 思路: 再输入时将最大和最小去掉,顺便统计非最值的和,输出时除一下个数即可. #include <bits/stdc++ ...

  2. COGS 696. [IOI1996][USACO 2.3] 最长前缀

    ★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构 ...

  3. Openjudge 2.5 6264:走出迷宫

    总时间限制:  1000ms 内存限制:  65536kB 描述 当你站在一个迷宫里的时候,往往会被错综复杂的道路弄得失去方向感,如果你能得到迷宫地图,事情就会变得非常简单. 假设你已经得到了一个n* ...

  4. 团队作业-Beta冲刺第三天

    这个作业属于哪个课程 <https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1> 这个作业要求在哪里 <https ...

  5. Kubernetes介绍与特性

    1.Kubernetes 是什么 简单的来说,k8s可以理解为,一个容器平台,一个微服务平台,便携式云平台,我们那可以很快速的搭建一个服务,快速的运行起来 2.Kubernetes特性

  6. js 监听页面url锚点变化 window.onpopstate

    window.onpopstate = function (event) { if (location.href.indexOf('#') == -1) { location.reload(); } ...

  7. C01 C语言基础

    目录 C语言简史及特点 C语言开发环境 C语言程序结构 C语言基本输入输出函数 编译 软件类型 C语言简要及特点 什么是计算机语言 计算机语言是用于人与计算机之间通讯的语言. 计算机遵照接收到的计算机 ...

  8. ios之NSURLRequest&NSURLConnection

    网络编程中一般都是经过  请求--->连接--->响应   (request  -->  connection  -->  response)这个过程. 一般的步骤是这样的: ...

  9. Fortran学习笔记5(数组Array)

    数组的声明方式 一维数组 二维数组 多维数组 数组索引值的改变 自定义类型的数组定义 对数组内容的设置 利用隐含式循环设置数组初值 对整个数组操作 对部分数组的操作 where函数 Forall函数 ...

  10. C++系统学习之三:向量

    标准库类型vector 定义:vector表示对象的集合,其中所有对象的类型都相同. 访问方式:索引 头文件:<vector> 本质:类模板 NOTE: 模板本身不是类或函数,相反可以将模 ...