题目链接: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. MVC Control 接收post请求的json数据

    [HttpPost] public string QueryInvoice() { string stream; using (var sr = new StreamReader(Request.In ...

  2. 使用 Ninject

    在[ASP.NET MVC 小牛之路]系列上一篇文章(依赖注入(DI)和Ninject)的末尾提到了在ASP.NET MVC中使用Ninject要做的两件事情,续这篇文章之后,本文将用一个实际的示例来 ...

  3. AutoFac之 Named and Keyed 方式注入

    AutoFac是.net framework下一个高效的ioc容器,传说中的效率最快(我偷偷看了几篇测试博文,确实这个容器的效率遥遥领先). 好了废话不多说,AutoFac的使用方式请看:http:/ ...

  4. 如何优雅地使用httprunner进行接口测试

    一天,你的领导X要你对某接口做测试,你一听,接口测试,高大上.用什么做好呢?postman?jmeter?loadrunner?balabala...优秀的你,想到了一大堆工具,当然也包括用pytho ...

  5. pat00-自测3. 数组元素循环右移问题 (20)

    00-自测3. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在 ...

  6. Linux getopt()函数 getopt_long()函数---转

    http://hi.baidu.com/scoundrelgg/item/d4083f8412eea05d26ebd97f Linux getopt()函数 getopt_long()函数 get_o ...

  7. 让ubuntu的ssh保持长时间连接

    Ubuntu下的ssh连接老是自己会断,一段时间不理它就会失去响应 如何让ssh连接服务器或者ssh tunnel保持连接呢? 其实也很方便,只要在/etc/ssh/ssh_config文件里加两个参 ...

  8. [转]什么?你还不会写JQuery 插件

    本文转自:http://www.cnblogs.com/joey0210/p/3408349.html 前言 如今做web开发,jquery 几乎是必不可少的,就连vs神器在2010版本开始将Jque ...

  9. C# 获取字符串长度

    int leng = System.Text.Encoding.Default.GetBytes(attachfileId2).Length;

  10. C#学习笔记13

    1.Task概述:Task是对操作系统线程的抽象,目的是使线程池能高效地管理线程的分配和回收,Task使用的底层线程属于一种共享资源,任务需要互相协作,并及时归还线程,以便用相同的共享资源(线程)满足 ...