直接按照题目给的代码抄一下然后保留最大的20位相互求一求最大LCM就行了。再注意一下细节,没什么难度其实。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ULL unsigned long long
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
int T, n, num, pos;
unsigned x, y, z, a[11000];
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;
}
unsigned gcd(unsigned a, unsigned b)
{
return b == 0 ? a : gcd(b, a%b);
}
ULL lcm(unsigned a, unsigned b)
{
ULL g = gcd(a, b);
return (ULL)a / g*(ULL)b;
}
int main()
{
scanf("%d", &T);
int cs = 0;
while (T--)
{
scanf("%d%u%u%u", &n, &x, &y, &z);
num = min(n, 20);
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++)
{
unsigned x = tang();
if (x>a[num - 1])a[num - 1] = x;
pos = num - 1;
while (pos&&a[pos] > a[pos - 1])
swap(a[pos], a[pos - 1]), pos--;
}
ULL res = 0;
for (int i = 0; i < num; i++)
for (int j = i + 1; j < num; j++)
res = max(res, lcm(a[i], a[j]));
printf("Case #%d: %llu\n", ++cs, res);
}
return 0;
}