链接:https://www.nowcoder.com/acm/contest/144/J
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
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
小结:一看这个题总以为要找特殊方法,结果之后就是暴力几十个最大的就行了,反思后是不敢去尝试,反正不会为何逃避。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define FIN freopen("D://code//in.txt", "r", stdin)
#define ppr(i,x,n) for(int i = x;i <= n;i++)
#define rpp(i,n,x) for(int i = n;i >= x;i--)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e7 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
inline int read() {//读入挂
int ret = 0, c, f = 1;
for(c = getchar(); !(isdigit(c) || c == '-'); c = getchar());
if(c == '-') f = -1, c = getchar();
for(; isdigit(c); c = getchar()) ret = ret * 10 + c - '0';
if(f < 0) ret = -ret;
return ret;
}
int cnt;
unsigned long long aa[maxn];
unsigned long long lcm(unsigned long long a,unsigned long long b)
{
return a/__gcd(a,b)*b;
}
unsigned a,b,c;
int main()
{
IO;
int n,t;
cnt = 1;
cin>>t;
while(t--)
{
cin>>n>>a>>b>>c;
for(int i = 1;i <= n;i++)
{
unsigned t;
a ^= a<<16;
a ^= a>>5;
a ^= a<<1;
t = a;
a = b;
b = c;
c = t ^ a ^ b;
aa[i] = c;
}
unsigned long long Max = aa[1] ;
if(n <= 26)
{
ppr(i,1,n-1)
ppr(j,i+1,n)
{
Max = max(Max,lcm(aa[i],aa[j]));
}
}
else
{
nth_element(aa+1,aa+n-25,aa+1+n);
ppr(i,n-25,n-1)
ppr(j,i+1,n)
{
Max = max(Max,lcm(aa[i],aa[j]));
}
}
printf("Case #%d: %llu\n",cnt++,Max);
}
return 0;
}