Rank3_小D的数字
时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte
总提交 : 1 测试通过 : 1
比赛描述
小D是一个喜欢数学的人,现在他有一个问题要和你分享:给你三个数,
随机从32位无符号整数(unsigned)整数中挑选,每次经过如下操作生成
一个数ai,一共经过n轮 ,生成n个数。现在他想知道这n个数中,lcm(ai,aj)的最大值(1<=i,j<=n) i ≠ j;
生成ai 的操作如下
unsigned x=A,y=B,z=C;
unsigned int tang()
{
unsigned int t;
x^=x<<16;
x^=x>>5;
x^=x<<1;
t=x;
x=y;
y=z;
z=t^x^y;
return z;
}
(提示:这个函数一共要调用n次,生成n个数,每一次的x,y,z都是和上一次有关的)
lcm 即最小公倍数
输入
一行 A,B,C (32位无符号整数)和n, 2<=n<=10000000;
输出
所求的结果
样例输入
2 1 2 3
样例输出
68516050958
题目来源
NUPT
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#define mem(x,y) memset(x,y,sizeof(x))
#define scan(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define eps 1e-8
#define INF 100000000
#define MAXN 500
#define rep(x,y,z) for(int x=y;x<=z;x++)
using namespace std;
typedef unsigned long long ll;
ll gcd(ll a,ll b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
if(a==0||b==0)
return 0;
return a/(ll)gcd(a,b)*b;
}
ll a[120];
int main()
{
unsigned int t,x,y,z;
int n,T;
ll temp;
scanf("%d%d%d%d",&n,&x,&y,&z);
for(int i=0;i<n;i++)
{
x^=x<<16;
x^=x>>5;
x^=x<<1;
t=x;
x=y;
y=z;
z=t^x^y;
//cout<<z<<endl;
if(z>a[0])
a[0]=z;
else
continue;
for(int j=1;j<100;j++)
{
if(a[j-1]>a[j])
{
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}
else
break;
}
}
ll maxn=0;
for(int i=0;i<100;i++)
for(int j=0;j<i;j++)
{
if(lcm(a[i],a[j])>maxn)
maxn=lcm(a[i],a[j]);
}
cout<<maxn<<endl;
return 0;
}