Topic

Test instructions: give you a number x and a number of q,x<=q, each time can be equal to the probability of x into [x,q] any number, asked to change the number of steps Q, output to 998244353 modulo, a number of queries

The first thing to be sure is that it can be preprocessed because it is only related to the difference of x,q

For the sake of understanding, we define F[P] to indicate the expectation of the number p to Q, for example, for q=10,f[9] to represent x=9, the desired number of steps

Then there is f[1] = 1/q * f[1]+1/q* f[2] +......+ 1/q * F[q-1] + 1

F[2] = 1/(q-1) * f[2] + ... +1/(q-1) * f[q-1]+1

......

F[Q-1]=1/2 * F[Q-1]+1 (e.g. example 7-8 expected steps 2)

So there is

(q-1)/q * F[1] = 1/q * (f[2]+f[3]+......+f[q-1]+q) (q-1) * f[1] = (f[2]+f[3]+......+f[q-1]+q)

(q-2)/(q-1) * f[2] = 1/(q-1) * (f[3]+f[4]+f[q-1]+q-1) (q-2) * f[2] = (f[3]+f[4]+f[q-1]+q-1)

......

1/2* F[q-1] =1/2 * 2

Because more than one group of queries, so put this array backwards processing to facilitate a little

Look at a lot of people code, found that the specific transfer can also be a lot of representations, may be defined as the time of f and different, anyway, was show

1#include <bits/stdc++.h>2 #defineMoD 998244353ll3 #definell Long Long4 #defineN 100000105 using namespacestd;6 intT,l,r;7 ll T,f[n],inv[n];8 intMain ()9 {Tenscanf"%d",&T); Oneinv[1]=1; A for(intI=2; i<n;i++) inv[i]= (mod-mod/i) *inv[mod%i]%MoD; - for(intI=1; i<n;i++) - { theF[i]= (t*inv[i]+ (i+1) *inv[i])%MoD; -T= (T+f[i])%MoD; - } - while(t--) + { -scanf"%d%d",&l,&R); +printf"%lld\n", f[r-l]); A } at}

Wannafly Challenge C expected operand math