# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1212298 | fadak-14 | Hack (APIO25_hack) | C++20 | 0 ms | 0 KiB |
#include "hack.h"
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define endl '\n'
#define eb emplace_back
#define em emplace
#define pb push_back
#define pf push_front
#define pp pop_back
#define fr first
#define sc second
#define sz size
using namespace std;
const int mx = 1e9;
signed hack() {
int s = mx / 2 + 1 ,e = mx ;
int v ,x ,md;
vector<int> tp , arr ;
while(s <= e) {
md = s + e >> 1 ,tp.clear() ;
x= (int)sqrt(md - s + 1) ;
for(int i =1 ; i <= x ; i++) tp.pb(i) ;
for(int i =1 ;s + i * x <= md; i++) tp.pb(s + i * x) ;
tp.pb(md + 1) ;
if(collisions(tp) > 0) e = md - 1 , v = md ;
else s = md + 1 ;
}
x = v ;
for(int i = 2 ; i * i <= v; i++) {
if(x % i) continue ;
arr.pb(i) ;
while(x % i == 0) x /= i ;
}
if(x > 1) arr.pb(x) ;
for(int i: arr) {
while(v%i == 0 && collisions({1 , v/ i + 1}) > 0) v/=i;
}
return v;
}