Given two sequences of N integers consisting of both positive and negative integers inclusive 0 (sequence A and sequence B). Then there will be Q queries, in each, you will be given two integers l and r (r>=l). Let’s define a function:
The task is to print the value of Max(f(x, y)) – Min(f(x, y)) for each query.
Input: N = 5, Q = 2 A = 0 7 3 4 5 B = 0 3 1 2 3 l = 1, r = 1 l = 1, r = 3 Output: 0 917448 Input: N = 5, Q = 2 A = 0 -8 3 4 -9 B = 0 -3 -5 2 3 l = 1, r = 1 l = 1, r = 3 Output: 0 851916
Approach: If we clearly see the function only depends on the value of x and y which can be easily calculated by seeing the nature of the summation of the individual arrays. First, we precalculate the prefix sum of both the arrays and then we just see the nature of the summations. And always the value of x and y will either be 32766 or -32766 as we are taking the modulo of them.
Below is the implementation of the above approach:
- Find (1^n + 2^n + 3^n + 4^n) mod 5 | Set 2
- Find 2^(2^A) % B
- Find value of (1^n + 2^n + 3^n + 4^n ) mod 5
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Find the value of f(n) / f(r) * f(n-r)
- Find larger of x^y and y^x
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Find x and y satisfying ax + by = n
- Find the sum of the series x(x+y) + x^2(x^2+y^2) +x^3(x^3+y^3)+ ... + x^n(x^n+y^n)
- Find sum of the series 1-2+3-4+5-6+7.......
- Find any pair with given GCD and LCM
- Find the value of N when F(N) = f(a)+f(b) where a+b is the minimum possible and a*b = N
- Find the sum of series 3, 7, 13, 21, 31....
- Find the sum of the series 2, 5, 13, 35, 97...
- Find (a^b)%m where 'a' is very large
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.