Number Theory and Binary Search

Description

Editorial

caution

Don’t read the editorial, if you have not attempted or read the problems. It would hamper your thinking capability, if you do so.

A. Find xF(n)x^{F(n)} mod m

Given 3 positive integers - xx, nn and mm. Find value of xF(n)x^{F(n)} mod mm .
The function F(n)F(n) is defined as the product of square of primes up to nn (inclusive).
For eg. F(5)=22β‹…32β‹…52=900F(5) = 2^2 \cdot 3^2 \cdot 5^2 = 900 .

Constraints

  • 1≀x,m≀1091 \leq x,m \leq 10^9
  • 2≀n≀1062 \leq n \leq 10^6

B. Simple Maths

You will be given 5 number nn ,mm , aa , bb , cc . You will make 3 more numbers AA , BB , CC from it.

A=aβ‹…mA = a \cdot m
B=Aβ‹…(b+c)B = A \cdot (b + c)
C=5β‹…B+Aβ‹…(floor(log⁑10(bβ‹…c)))C = 5 \cdot B + A \cdot (floor(\log_{10}{(b \cdot c)}))

You task is to computer f(n)f(n) % mm where
f(i)=(Aβ‹…i9+iiβ‹…(Bβ‹…i!+1)+Cβ‹…iii)β‹…f(iβˆ’1)f(i) = (A \cdot i^9 + i^i \cdot (B \cdot i!+1) + C \cdot i^{i^i}) \cdot f(i-1)

Note : f(0)=1f(0) = 1

Constraints

  • 1≀n≀10181 \leq n \leq 10^{18}
  • 1≀m≀1061 \leq m \leq 10^6
  • 1≀a,b,c≀10121 \leq a,b,c \leq 10^{12}

C. Candy Distribution

In the Town of Candyland, there are KK candy vendors who need to distribute candies to the kids of the town. Candyland can be represented as the x-axis where kids are standing at different xx coordinates, which are given to you. A vendor can only serve kids which are in his range, for example, if a vendor is placed at XX and his range is EE then all kids in the range [Xβˆ’E,X+E][X-E,X+E] can get candies from him. All the vendors have an equal range EE.

Since the vendors are lazy so they want you to find the minimum range EE such that all the kids in Candyland can get candies.

Constraints

  • 1≀n,k≀1041 \leq n,k \leq 10^4
  • 10βˆ’9≀Xi≀10910^{-9} \leq X_i \leq 10^{9}

D. Seems to be easy xD

Given an array AA (having the values of all elements in range [0,2000] ) of length NN.
Each index i∈[1,N]i ∈ [1,N] has an initial weight of WiW_i units. You have to perform QQ queries. The queries can be of 2 types:

Type 11: 11 XX
Type 22: 22 VV LL RR

Type 11 queries ask you to increase the weight of all indices by XX units.

Type 22 queries ask you to calculate the total weight contributed by elements having value VV in the index range [L,R][L,R]

Constraints

  • 1≀N,Q≀5β‹…1051 \leq N,Q \leq 5 \cdot 10^5
  • 1≀Ai,V≀20001 \leq A_i,V \leq 2000
  • 0≀Wi,X≀1000 \leq W_i, X \leq 100
  • 1≀L≀R≀N1 \leq L \leq R \leq N

E. Rahul and his set

Rahul has a set SS consisting of the first NN natural numbers.

He thinks that 'wellness' of a subset MM βŠ† SS is equal to the maximum of gcd(a,b)gcd(a,b) over all pairs (a,b)(a,b) such that both aa and bb are in MM and aβ‰ ba \neq b.

Rahul is an organized guy and for each kk ∈ {2,3,…,N2,3,…,N} he wants to find a subset that has the smallest wellness among all subsets in SS of size kk. There can be more than one subset with the smallest wellness and the same size, but you don't need to worry about it. Rahul wants to find all the subsets himself, but he needs your help to find the smallest possible wellness for each size kk, will name it IkI_k.

Please, help Rahul to find I2,I3,...,InI_2, I_3, ..., I_n.

Constraints

  • 2≀N≀5β‹…1052 \leq N \leq 5 \cdot 10^5