Found 1860 Articles for Data Structure

Vantieghems Theorem for Primality Test

Rinish Patidar
Updated on 28-Aug-2023 18:09:42

162 Views

The problem statement includes using Vantieghems theorem for primality test i.e. we will check for a positive number N which will be user input and print if the number is a prime number or not using the Vantieghems theorem. Vantieghem’s Theorem The Vantieghems theorem for primality states that a positive number, N is a prime number if the product of $\mathrm{2^{i}−1}$ where the value of i ranges from 1 to N−1 is congruent to N modulo $\mathrm{2^{N}−1}$ If both the values are congruent then the number N is a prime number else it is not a prime number. Congruent ... Read More

Sum of Range in a Series of First Odd then Even Natural Numbers

Rinish Patidar
Updated on 28-Aug-2023 17:59:41

176 Views

The problem statement includes finding the sum of range in a series of first odd numbers then even natural numbers up to N. The sequence consists of all the odd natural numbers from 1 to N and then all the even natural numbers from 2 to N, including N. The sequence will be of size N. We will be provided with a range in the problem for which we need to find out the sum of the sequence within that range, a and b i.e. [a, b]. Here a and b are included in the range. For example, we are ... Read More

Sum of product of Consecutive Binomial Coefficients

Rinish Patidar
Updated on 28-Aug-2023 17:54:20

301 Views

The problem statement includes printing the sum of product of consecutive binomial coefficients for any positive number, N which will be the user input. The positive coefficients in the binomial expansion of any term are called binomial coefficients. These binomial coefficients can be found out using Pascal's triangle or a direct formula. The formula to calculate the binomial coefficient: $$\mathrm{^nC_{r}=\frac{n!}{(n-r)!r!}}$$ where, n and r can be any positive numbers and r should never be greater than n. Note : The value of 0! is always equal to 1. In this problem, we will be given a positive number N and ... Read More

Sum of digits written in different bases from 2 to n-1

Rinish Patidar
Updated on 28-Aug-2023 17:50:33

170 Views

The problem statement includes printing the sum of digits of N, which will be the user input, when written in different bases from 2 to N−1. In this problem, we will be provided any positive integer N and we need to represent that number in a different base numeral system from 2 to N−1 and find the sum of the digit of each different base numeral system. In the base−n numeral system, every digit of the representation of any number in that numeral system from right represents the number of times power of n from 0 to 31. For example, ... Read More

Sum of bitwise OR of all possible subsets of given set

Rinish Patidar
Updated on 28-Aug-2023 17:46:06

356 Views

The problem statement includes printing the sum of bitwise OR of all possible subsets of a given set. A set is a collection of data of similar type. A subset of any set is a set containing few elements of the set or all the elements of the given set. The number of subsets of any set is given by $\mathrm{2^{n}−1}$, where n is the number of elements in the given set. For example, a={1, 2, 3, 4, 5} is the given set. {1}. {2, 3}, {1, 2, 3, 4} and so on are called subsets of a, as they ... Read More

Program to print the sum of the given nth term

Rinish Patidar
Updated on 28-Aug-2023 17:34:54

364 Views

The problem statement includes printing the sum of the series whose Nth term is given. The value of N will be given in the input. We need to find the sum of the sequence up to N where the Nth term of the sequence is given by: $$\mathrm{N^{2}−(N−1)^{2}}$$ Let’s understand the problem with the below examples: Input N=5 Output 25 Explanation − The value of N given is 5.The first 5 terms of the sequence are: $\mathrm{N=1, 1^{2}−(1−1)^{2}=1}$ $\mathrm{N=2, 2^{2}−(2−1)^{2}=3}$ $\mathrm{N=3, 3^{2}−(3−1)^{2}=5}$ $\mathrm{N=4, 4^{2}−(4−1)^{2}=7}$ $\mathrm{N=5, 5^{2}−(5−1)^{2}=9}$ The sum of the terms of the sequence until 5th ... Read More

Numbers within a range that can be expressed as power of two numbers

Rinish Patidar
Updated on 28-Aug-2023 15:39:32

387 Views

The problem statement includes printing the count of numbers within a range given that can be expressed as power of two numbers i.e. numbers which are perfect powers. The numbers which are known as perfect powers is the number which can be expressed as $\mathrm{x^{y}}$, where x>0 and y>1 for all integers. For example, 8 is a perfect power because it can be expressed as $\mathrm{2^{3}}$, which is equal to 8 hence it is considered as a perfect power. In this problem, we will be given a range as two positive integers in the input i.e. a and b ... Read More

Minimum digits to remove to make a number Perfect Square

Rinish Patidar
Updated on 28-Aug-2023 15:36:03

578 Views

The problem statement includes finding the minimum number of digits to remove from a number to make a number perfect square. A perfect square denoted as $\mathrm{x^{2}}$ is a positive integer which is a product of an integer with itself. We will be given a positive number N and we need to find the minimum number of digits we can remove from the number N to make it a perfect square i.e. such that it is a product of some integer with itself. For example, N=42 We can remove 1 digit from N i.e. 2 to make it a perfect ... Read More

Making zero array by decrementing pairs of adjacent

Rinish Patidar
Updated on 28-Aug-2023 15:34:10

131 Views

The problem statement includes making an array zero array by decrementing pairs of adjacent. The array will be given in the input and we can perform the operation on the array i.e. subtract 1 from ith and (i+1)th index where 0

Java Math subtractExact(long x, long y) method

Revathi Satya Kondra
Updated on 28-Jan-2025 11:39:30

462 Views

We will discuss the Java Math subtractExact(long x, long y) method in Java and understand its functionalities and working. The subtractExact()is an inbuilt function in the Java Math library. The function returns the difference between the two parameters passed as arguments in the function. The function returns an exception when the returned value overflows the range of values of a particular data type. It is the most commonly used class for mathematical operations is the java.lang.Math class is a part of the Java Standard Library and is included in the java.lang package. Syntax Following is the syntax of the subtractExact() function ... Read More

Advertisements