链接: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 ≤ 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,a,b,c根据 构造 获得an[] 数组
然后求数组内 两个数的 最大 LCM...
骚操作 nth_element 哈哈
作用就是, 把 某个元素放在该放的位置上,然后前面的都比他小,后面的都比他大...
sort 会超时....
我们 暴力后三十项--- 求 最大 LCM...
代码:
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i = n; i>=a;i--)
#define SI(x) scanf("%d",&x)
#define pb push_back
typedef unsigned long long ll;
const int maxn = 1e7+10;
using namespace std;
unsigned x,y,z;
unsigned tang()
{
unsigned t;
x^=x<<16;
x^=x>>5;
x^=x<<1;
t = x;
x = y;
y = z;
z = t^x^y;
return z;
}
ll ans[maxn];
int main()
{
int t;
SI(t);
int cot =0;
int n,a,b,c;
while(t--)
{
SI(n),SI(a),SI(b),SI(c);
x = a;y = b;z = c;
rep(i,0,n-1)
ans[i]=tang();
nth_element(ans,ans+max(0,n-100),ans+n);
ll res = 0;
rep(i,max(0,n-100),n-1)
{
rep(j,i+1,n-1)
{
ll temp = 1ll*ans[j]/__gcd(ans[i],ans[j])*ans[i];
res =max(temp,res);
}
}
printf("Case #%d: %llu\n",++cot,res);
}
return 0;
}