Sunday, 28 Nov 2021
Category: maths-power

Given three integers A, N and P, the task is to find (A^(N!)) % P.Examples:Input: A = 2, N = 1, P = 2Output: 0Explanation: As (2^(1!)) = 2Therefore 2 % 2 will be 0.Input: A = 3, N = 3, P = 2Output: 1Naive Approach: The simplest solution of this problem can be find […]

Reduce the given Array of [1, N] by rotating left or right based on given conditionsGiven a sorted array arr[] of the first N Natural Numbers and an integer X, the task is to print the last remaining element after performing the below operations (N – 1) times:Examples:Input: N = 5, arr[] = {1, 2, […]

Mean of fourth powers of first N natural numbersGiven a positive integer N, the task is to find the average of the fourth powers of the first N natural numbers.Examples:Input: N = 3Output: 32.6667Explanation:Sum of the fourth powers of the first N natural numbers = 14 + 24 + 34 = 1 + 16 + […]

Number of relations that are neither Reflexive nor Irreflexive on a SetGiven a positive intege N, the task is to find the number of relations that are neither reflexive nor irreflexive on a set of first N natural numbers. Since the count of relations can be very large, print it to modulo 109 + 7.A […]

Count numbers up to N that cannot be expressed as sum of at least two consecutive positive integersGiven a positive integer N, the task is to find the count of integers from the range [1, N] such that the integer cannot be expressed as sum of two or more consecutive positive integers.Examples:Input: N = 10Output: […]

Given a positive integer N, the task is to find the number of relations that are irreflexive antisymmetric relations that can be formed over the given set of elements.  Since the count can be very large, print it to modulo 109 + 7.A relation R on a set A is called reflexive if no (a, […]

Quadratic equation whose roots are K times the roots of given equationGiven three integers A, B, and C representing the coefficients of a quadratic equation Ax2 + Bx + C = 0 and a positive integer K, the task is to find the coefficients of the quadratic equation whose roots are K times the roots […]

import java.io.*;import java.lang.*;import java.util.*;class GFG{static boolean isPowerOfTwo(int n){             if (n == 0)        return false;        return (Math.ceil(Math.log(n) / Math.log(2)) ==           Math.floor(Math.log(n) / Math.log(2)));}static void printArray(ArrayList res){             Collections.sort(res);        for(int i = 0; i < res.size(); i++)    {        System.out.print(res.get(i) + " ");    }}static void sortedStrings(String S[], int N){                 HashMap freq = new HashMap();            ArrayList res = new ArrayList();        for(int i = 0; i < N; i++)    {                         String st = "";                        for(int j […]

Modify array by replacing elements with the nearest power of its previous or next elementGiven a circular array arr[] consisting of N positive integers, the task is to modify the array by replacing each array element with the nearest power of its previous or next array element.Examples:Input: arr[] = {2, 3, 4, 1, 2}Output: {2, […]

Minimum increments or decrements required to convert a sorted array into a power sequence Given a sorted array arr[] consisting of N positive integers, the task is to minimize the total number of increments or decrements of each array element required to convert the given array into a power sequence of any arbitrary integer X. […]