# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1125154 | AlgorithmWarrior | 마술쇼 (APIO24_show) | C++17 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "Alice.h"
using namespace std;
vector<pair<int,int>>Alice(){
long long x=setN(5000);
int i;
vector<pair<int,int>>tree;
for(i=2;i<=5000;++i){
tree.push_back({x%(i-1)+1,i});
}
return tree;
}
#include <bits/stdc++.h>
#include "Bob.h"
using namespace std;
long long bin_exp(long long base,long long exp,long long mod){
long long rez=1;
while(exp){
if(exp&1){
rez=rez*base%mod;
}
base=base*base%mod;
exp/=2;
}
return rez;
}
long long CRT(long long r1,long long m1,long long r2,long long m2){
long long g=__gcd(m1,m2);
long long k=(r2-r1)/g*bin_exp(m1/g,m2/g-2,m2/g)%(m2/g);
long long x=m1*k+r1;
return x;
}
long long Bob(vector<pair<int,int>>V){
long long x=0;
long long mod=1;
for(auto edge : V){
x=CRT(x,mod,edge.first-1,edge.second-1);
if(mod>1e18/(edge.second-1)*__gcd(mod,edge.second-1))
break;
mod=mod*(edge.second-1)/__gcd(mod,1LL*edge.second-1);
}
return x;
}