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

直接按照题目给的代码抄一下然后保留最大的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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值