牛客多校第六场 J题 Heritage of skywalkert

Heritage of skywalkert
题 意:给你n个数字,1<=i,j <=n,让你求(ai,aj)的最大的最小公倍数。
数据范围:
2<=n<=1e7
ai的输入调用以下函数
这里写图片描述

输入样例:

2
2 1 2 3
5 3 4 8

输出样例:

Case #1: 68516050958
Case #2: 5751374352923604426

思 路:n有1e7,所以n^2的复杂度肯定是不行的,其实只要拿前n个中前100最大的去求他们的最大的最小公倍数就可以了。
收 获:unsigned 在那个范围就用那个范围去存,尽量不要开太大,可能出问题。记住一个结论。有时候,可以有依据的去尝试猜结论。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
priority_queue<ull,vector<ull>,greater<ull> > que;
int T,n;
ui b[11000];
ui A,B,C;
ui x,y,z;
ui ca(){
    ull t;
    x^=x<<16;
    x^=x>>5;
    x^=x<<1;
    t=x;
    x=y;
    y=z;
    z=t^x^y;
    return z;
}
ui gcd(ui a,ui b){
    return b==0?a:gcd(b,a%b);
}
int main(){
    int Kase = 1;
    scanf("%d",&T);
    while(T--){
        cin>>n>>A>>B>>C;
        x = A;
        y = B;
        z = C;
        for(int i=0;i<n;i++){
            ui p = ca();
            if(que.size()>10){
                if(que.top() < p){
                    que.pop();
                    que.push(p);
                }
            }else{
                que.push(p);
            }
        }
        int pos = 0;
        while(que.size()){
            b[pos++] = que.top();
            que.pop();
        }
        ull ans = 0;
        for(int i=0;i<pos;i++){
            for(int j=i+1;j<pos;j++){
                ans = max(ans,(ull)b[i]*b[j]/(ull)gcd(b[i],b[j]));
            }
        }
        printf("Case #%d: ",Kase++);
        cout<<ans<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值