Sunday, 28 Nov 2021
Category: maths-power

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 + […]

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: […]

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 […]