Wannafly Challenge C expected operand math

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.