题目链接: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. (转)同步异步,阻塞非阻塞 和nginx的IO模型

    同步异步,阻塞非阻塞 和nginx的IO模型  原文:https://www.cnblogs.com/wxl-dede/p/5134636.html 同步与异步 同步和异步关注的是消息通信机制 (sy ...

  2. 解决dns服务器未找到问题 &&DNS解析服务器&&连接问题

    第一部分: 有时已经连接到了网络,但是却提示未找到dns服务器,或未连接dns服务器,这多是因为dns设置的问题.下面是几种可行的解决方法. 方法一: 1. win + R   -> cmd - ...

  3. TOJ 4393 Game

    描述 Bob always plays game with Alice.Today,they are playing a game on a tree.Alice has m1 stones,Bob ...

  4. ElasticSearch mapping中字段属性总结

  5. LeetCode 319 ——Bulb Switcher——————【数学技巧】

    319. Bulb Switcher My Submissions QuestionEditorial Solution Total Accepted: 15915 Total Submissions ...

  6. HRBUST 1161——Leyni——————【线段树单点更新,区间查询】

    Leyni Time Limit: 3000 MS Memory Limit: 65536 KB 64-bit integer IO format: %lld , %llu Java class na ...

  7. RequireJS 2.0 正式发布

    就在前天晚上RequireJS发布了一个大版本,直接从version1.0.8升级到了2.0.随后的几小时James Burke又迅速的将版本调整为2.0.1,当然其配套的打包压缩工具r.js也同时升 ...

  8. goto语句和标签

    goto 语句用于将执行流更改到标签处,虽然t-sql和pl/sql都提供了该语句,但是作为编程而言,我们不推荐使用此编程技术.要编写一个标签,应当在标识符后面加一个冒号.列如,下面示例使用goto语 ...

  9. 【读书笔记】C#高级编程(一).NET体系结构

    写在前面:从业两年来,一直停留在会用的阶段,而没有去仔细思考过为什么这么用,之前也大致扫过<c#高级编程>一书,这次想借一袭脑海中的冲动,再次好好仔细过过这本书,夯实基础,温故知新. 一. ...

  10. json对象字符串互转

    json对象字符串互转 1.Node.js中 JSON.parse(jsonstr); //可以将json字符串转换成json对象 JSON.stringify(jsonobj); //可以将json ...