牛客网暑期ACM多校训练营(第六场)J(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 牛客网暑期ACM多校训练营(第六场)J(Heritage of skywalkert). 牛客网暑期ACM多校训练营(第六场)J(Heritage of skywalkert) 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.

牛客网暑期ACM多校训练营(第六场)J(Heritage of skywalkert)

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

题意:给出初始的A,B,C,按照题目中迭代n次求n个z,然后求这n个数中的两个数lcm的最大值。

思路:这道题有毒。长见识了。

保留最大的20项,然后暴力求就能过。大多数人是保留的100项也可以。

代码:

#include<bits/stdc++.h>
using namespace std;
using LL=unsigned long long;
using ui=unsigned int;
unsigned x,y,z,a[10000007];
int T,n;
LL ans;
ui tang(){
    x^=x<<16;
    x^=x>>5;
    x^=x<<1;
    ui zz=x^y^z;
    x=y;
    y=z;
z=zz;
    return zz;
}
template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
#define lcm(a,b) ((LL)(a)/gcd(a,b)*(b))
int main()
{
    scanf("%d",&T);
    for(int t=1;t<=T;t++)
    {
        ans=0;
        scanf("%d%u%u%u",&n,&x,&y,&z);
        for(int i=1;i<=n;i++)  a[i]=tang();
        nth_element(a,a+n-13,a+n);
        for(int i=max(n-13,1);i<=n;i++)
            for(int j=i+1;j<=n;j++)
                ans=max({ans,lcm(a[i],a[j])});
        printf("Case #%d: %llu\n",t,ans);
    }
}