# Tag Archives: number-theory

## Program to find first N Fermat Numbers

Fermat numbers are non-negative odd numbers which is valid for all values of k>=0. Only the first seven terms of the sequence are known till… Read More »

## Modular Exponentiation of Complex Numbers

Given four integers A, B, K, M. The task is to find (A + iB)K % M which is a complex number too. A +… Read More »

## Count non-negative triplets with sum equal to N

Given an integer N. The task is to find the number of different ordered triplets(a, b, c) of non-negative integers such that a + b… Read More »

## Find a number containing N – 1 set bits at even positions from the right

Given a positive integer N, the task is to find a number which contains (N – 1) set bits in its binary form at every… Read More »

## Number of elements from the array which are reachable after performing given operations on D

Given an array arr[] and three integers D, A and B. You start with the number D and at any time you can add or… Read More »

## Print first N Mosaic numbers

Given an integer N, the task is to print first N Mosaic numbers. A Mosaic number can be expressed as follows: If N = p1a1p2a2…pkak… Read More »

## Number of ways of writing N as a sum of 4 squares

Given a number N, the task is to find the number of ways of writing N as a sum of 4 squares. Two representations are… Read More »

## Find the Nth Mosaic number

Given an integer N, the task is to find the Nth Mosaic number. A Mosaic number can be expressed as follows: If N = Aa… Read More »

## Count Distinct Rectangles in N*N Chessboard

Given a N x N Chessboard. The task is to count distinct rectangles from the chessboard. For example, if the input is 8 then the… Read More »

## Sum of all perfect numbers present in an array

Given an array arr[] containing N positive integer. The task is to find the sum of all the perfect numbers from the array. A number… Read More »

## Check if each element of the given array is the product of exactly K prime numbers

Given an array of numbers and the value of , check if each number can be expressed as the product of exactly prime numbers. For… Read More »

## New Algorithm to Generate Prime Numbers from 1 to Nth Number

Apart from Sieve of Eratosthenes method to generate Prime numbers, we can implement a new Algorithm for generating prime numbers from 1 to N. It… Read More »

## Predict the winner in Coin Game

There are two players P1 and P2 and two piles of coins consisting of M and N coins respectively. At each turn, a player can… Read More »

## Print all numbers whose set of prime factors is a subset of the set of the prime factors of X

Given a number X and an array of N numbers. The task is to print all the numbers in the array whose set of prime… Read More »

## 3-digit Osiris number

Given a 3-digit number N, the task is to find if N is an Osiris number or not. Osiris numbers are the numbers that are… Read More »