1. 程式人生 > ><牛客多校round 6>

<牛客多校round 6>

walk close span ase pri bsp its std round

Solved:3

rank:156

J. Heritage of skywalker

學習一下nth_element 可以o (n)的找出前多少大的元素

技術分享圖片
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int n;
unsigned x, y, z;

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; } ull gcd(ull x, ull y) { if(y == 0) return x; return gcd(y, x % y); } ull q[10000005]; int main() { int T; scanf("%d", &T); int cas = 0; while(T--) { cas++; cin>>n>>x>>y>>z;
for(int i = 0; i < n; i++) q[i] = tang(); int len = min(100, n); nth_element(q, q + len, q + n, greater<ull>()); ull ans = 0; for(int i = 0; i < len; i++) { for(int j = i + 1; j < len; j++) { ull tmp = gcd(q[i], q[j]); ans
= max(ans, q[i] / tmp * q[j]); } } printf("Case #%d: %llu\n", cas, ans); } return 0; }
View Code

<牛客多校round 6>