https://www.nowcoder.com/acm/contest/144/J
题意:通过一个操作得到ai,然后找到两个数,使得他们的lcm最大。
思路:得到的数其实相当于随机数,只要找前20大的数暴力找他们的lcm即可,可以用优先队列来找前20大的,直接排序会时间会炸
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
priority_queue<ull,vector<ull>,greater<ull> > que;
unsigned x,y,z;
int n;
unsigned a[55];
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;
}
ull gcd(ull a,ull b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int main()
{
int T;
int cas=0;
scanf("%d",&T);
while(T--)
{
cin>>n>>x>>y>>z;
for(int i=0;i<n;i++)
{
ull p=tang();
if(que.size()>20)
{
if(que.top()<p)
{
que.pop();
que.push(p);
}
}
else que.push(p);
}
int k=0;
while(!que.empty())
{
a[k++]=que.top();
que.pop();
}
sort(a,a+k);
ull ans=0;
ull g;
for(int i=0;i<k;i++)
{
for(int j=i+1;j<k;j++)
{
g=gcd(a[j],a[i]);
ans=max(ans,(ull)a[i]/g*a[j]);
}
}
cout<<"Case #"<<++cas<<": "<<ans<<endl;
}
return 0;
}