# Tag Archives: number-theory

## Sum of first n odd numbers in O(1) Complexity

Given the sequence of odd numbers 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, …. Find the sum of first n… Read More »

## K-Primes (Numbers with k prime factors) in a range

Given three integers A, B and K. We need to find no. of K-prime numbers in the range [A, B]. A number is called K-prime… Read More »

## Fermat’s little theorem

Fermat’s little theorem states that if p is a prime number, then for any integer a, the number a p – a is an integer… Read More »

## Queries to print all divisors of number

Given a positive integer ‘n’ and query ‘q’. Print all the divisors of number ‘n’. Input: 6 Output: 1 2 3 6 Explanation Divisors of… Read More »

## Largest number by which given 3 numbers should be divided such that they leaves same remainder

Given three numbers, our task is to find the largest number by which when given 3 numbers are divided leads to same remainder. It may… Read More »

## Maximum factors formed by two numbers

Given a list of N numbers, Find two numbers such that the product of the two numbers has the maximum number of factors. Formally given… Read More »

## Given two numbers a and b find all x such that a % x = b

Given two numbers a and b find all x such that a % x = b . Examples: Input : a = 21, b =… Read More »

## Find a Number X whose sum with its digits is equal to N

Given a positive number N. We need to find number(s) such that sum of digits of those numbers to themselves is equal to N. If… Read More »

## Check whether a number can be represented by sum of two squares

We have a number n. We need to find whether number n can be represented by the sum of two squares. Examples : Input :… Read More »

## Divisors of n-square that are not divisors of n

Given an positive large integer n. Count the number of positive divisors of n2 which are not divisible by any divisor of n(1 <= n… Read More »

## Prime numbers and Fibonacci

Given a number, find the numbers (smaller than or equal to n) which are both Fibonacci and prime. Examples: Input : n = 40 Output:… Read More »

## Representation of a number in powers of other

Given two numbers w and m, we need to determine whether it is possible to represent m in terms of powers of w. The powers… Read More »

## Count ways to express even number ‘n’ as sum of even integers

Given an positive even integer ‘n’. Count total number of ways to express ‘n’ as sum of even positive integers. Output the answer in modulo… Read More »

## Check if given number can be represented as sum of two great numbers

We are given a number N. We need to check if the given number N can be represented as sum of two Great numbers. If… Read More »

## Largest power of k in n! (factorial) where k may not be prime

Given two numbers k and n, find the largest power of k that divides n! Constraints: K > 1 Examples: Input : n = 7,… Read More »