# Tag Archives: number-theory

## Taxicab Numbers

The nth Taxicab number Taxicab(n), also called the n-th Hardy-Ramanujan number, is defined as the smallest number that can be expressed as a sum of… Read More »

## Betrothed numbers

Betrothed numbers are two positive numbers such that the sum of the proper divisors of either number is one more than (or one plus) the… Read More »

## Program to find sum of first n natural numbers

Given a number n, find the sum of first natural numbers. Examples : Input : n = 3 Output : 6 Explanation : Note that… Read More »

## Number of digits in the product of two numbers

Given two integers a and b. The problem is to find the number of digits in the product of these two integers. Examples: Input :… Read More »

## Sum of cubes of first n odd natural numbers

Given a number n, find sum of first n odd natural numbers. Input : 2 Output : 28 1^3 + 3^3 = 28 Input :… Read More »

## Sum of cubes of first n even numbers

Given a number n, find sum of first n even natural numbers. Examples: Input : 2 Output : 72 2^3 + 4^3 = 72 Input… Read More »

## An interesting solution to get all prime numbers smaller than n

This approach is based on Wilson’s theorem and using the fact that factorial computation can be done easily using DP Wilson theorem says if a… Read More »

## Lexicographic rank of a string using STL

You are given a string, find its rank among all its permutations sorted lexicographically. Examples: Input : str[] = “acb” Output : Rank = 2… Read More »

## Find minimum sum of factors of number

Given a number, find minimum sum of its factors. Examples: Input : 12 Output : 7 Explanation: Following are different ways to factorize 12 and… Read More »

## Pell Number

Pell numbers are numbers that are similar to the Fibonacci numbers and are generated by below formula Pn = 2*Pn-1 + Pn-2 with seeds P0… Read More »

## Demlo number (Square of 11…1)

Given a number of the form 11..1 such that number of digits in it is smaller than 10, find square of the number. Examples: Input… Read More »

## Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B

Given a number n. We need find the number of ordered pairs of a and b such gcd(a, b) is b itself Examples : Input… Read More »

## Break the number into three parts

Given a really large number, break it into 3 whole numbers such that they sum up to the original number and count number of ways… Read More »

## Number Theory (Interesting Facts and Algorithms)

Questions based on various concepts of number theory and different types of number are quite frequently asked in programming contests. In this article, we discuss… Read More »

## Paytm Interview Experience | Set 15

Round I Say millions of players are playing a game online and their scores keep changing. Every player is represented by ID and SCORE. How… Read More »