题解 P10539 - [APIO2024] 魔术表演
这里讲一下赛时 20 分钟想到的垃圾做法。
对于 Alice,我们充分发扬人类智慧,考虑对任意
对于 Bob 只需把所有边的信息都用数论知识合并起来即可得出
事实上,本题不需要 excrt,因为
事实上,在交互库足够强的情况下,
#include<bits/stdc++.h>
#include"Alice.h"
using namespace std;
const int N=5000;
vector<pair<int,int>> Alice(){
long long x=setN(N);
vector<pair<int,int>> edges;
for(int i=2;i<=N;i++)
edges.emplace_back(x%(i-1)+1,i);
return edges;
}
#include<bits/stdc++.h>
#include"Bob.h"
using namespace std;
long long Bob(vector<pair<int,int>> edges){
__int128 answer=0,nowmod=1;
for(pair<int,int> edge :edges){
int r=edge.first-1,mod=edge.second-1;
while(answer%mod!=r)answer+=nowmod;
nowmod*=mod/__gcd(nowmod,(__int128)mod);
if(nowmod>1e18)return answer;
}
return answer;
}
考虑优化,容易发现在最初的做法中,一些素数只要删除一次或者两次就无法对答案造成贡献,这样会产生大量的信息浪费,所以考虑构造
如果令
1 2 3 4 5 5 7 7 9 9 11 11 11 13 13 13 16 17 17 17 19 19 19 23 23 23 25 25 27 29 29 29 29 31 31 31 31 32 37 37 37 37 41 41 41 41 43 43 43 43 47 47 47 47 49 49 53 53 53 53 59 59 59 59 61 61 61 61 64 67 67 67 67 71 71 71 71 71 73 73 73 73 79 79 79 79 83 83 83 83 83 89 89 89 89 79 97 97
直觉上
附:最简易的数论做法需要