# 「PKUWC2018」猎人杀

## 「PKUWC2018」猎人杀

$P =\dfrac{w_i}{W-T}$

$P=\dfrac{T}{W}P+\dfrac{w_i}{W} \\ \dfrac{W-T}{W}P=\dfrac{w_i}{W} \\ P=\dfrac{w_i}{W-T}$

$Ans =\sum_S (-1)^{|S|}\sum_{i=0}^{\infty} (1-\frac{sum(S)+w_1}{W})^i\frac{w_1}{W}\\$

$Ans =\sum _{S}(-1)^{|S|}\frac{W}{sum(S)+w_1}\times \frac{w_1}W{}\\ Ans = w_1\sum _{S}\dfrac{(-1)^{|S|}}{sum(S)+w_1}$

$F(x)=\prod_{i=2}^n(1-x^{w_i}) \\ Ans = w_1\sum_{i=0}^{W-w_1}\dfrac{[x^i]F(x)}{i+w_1}$

#### code

/*program by mangoyang*/
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
int ch = 0, f = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
}
const int N = (1 << 21), P = 998244353, G = 3;
namespace poly{
int rev[N], len, lg;
inline int Pow(int a, int b){
int ans = 1;
for(; b; b >>= 1, a = 1ll * a * a % P)
if(b & 1) ans = 1ll * ans * a % P;
return ans;
}
inline void timesinit(int lenth){
for(len = 1, lg = 0; len <= lenth; len <<= 1, lg++);
for(int i = 0; i < len; i++)
rev[i] = (rev[i>>1] >> 1) | ((i & 1) << (lg - 1));
}
inline void DFT(int *a, int sgn){
for(int i = 0; i < len; i++)
if(i < rev[i]) swap(a[i], a[rev[i]]);
for(int k = 2; k <= len; k <<= 1){
int w = Pow(G, (P - 1) / k);
if(sgn == -1) w = Pow(w, P - 2);
for(int i = 0; i < len; i += k){
int now = 1;
for(int j = i; j < i + (k >> 1); j++){
int x = a[j], y = 1ll * now * a[j+(k>>1)] % P;
a[j] = x + y >= P ? x + y - P : x + y;
a[j+(k>>1)] = x - y < 0 ? x - y + P : x - y;
now = 1ll * now * w % P;
}
}
}
if(sgn == -1){
int INV = Pow(len, P - 2);
for(int i = 0; i < len; i++) a[i] = 1ll * a[i] * INV % P;
}
}
}
using poly::Pow;
using poly::DFT;
using poly::timesinit;
int a[N], b[N], w[N], n;
inline vector<int> solveNTT(int l, int r){
if(l == r){
vector<int> vec;
vec.resize(w[l] + 1), vec[0] = 1, vec[w[l]] = P - 1;
return vec;
}
int mid = (l + r) >> 1;
vector<int> A = solveNTT(l, mid);
vector<int> B = solveNTT(mid + 1, r);
int lenth = (int) A.size() + (int) B.size() - 1;
for(int i = 0; i < (int) A.size(); i++) a[i] = A[i];
for(int i = 0; i < (int) B.size(); i++) b[i] = B[i];
timesinit(lenth);
DFT(a, 1), DFT(b, 1);
for(int i = 0; i < poly::len; i++) a[i] = 1ll * a[i] * b[i] % P;
DFT(a, -1);
vector<int> vec;
for(int i = 0; i < lenth; i++) vec.push_back(a[i]);
for(int i = 0; i < poly::len; i++) a[i] = b[i] = 0;
return vec;
}
int main(){
}