Finding sum of digits of a number until sum becomes single digit
Given a number n, we need to find the sum of its digits such that: If n < 10 digSum(n) = n Else digSum(n) =… Read More »
Given a number n, we need to find the sum of its digits such that: If n < 10 digSum(n) = n Else digSum(n) =… Read More »
ACM ICPC(Association for Computing Machinery – International Collegiate Programming Contest) is a world-wide annual multi-tiered programming contest being organized for over thirteen years. The contest… Read More »
A number n is said to be a Carmichael number if it satisfies the following modular arithmetic condition: power(b, n-1) MOD n = 1, for… Read More »
Given a positive integer n, and that it is composite, find a divisor of it. Example: Input: n = 12; Output: 2 [OR 3 OR… Read More »
Given a large number n and a prime p, how to efficiently compute n! % p? Examples : Input: n = 5, p = 13… Read More »
In this post “Important top 10 algorithms and data structures for competitive coding “. Topics : Graph algorithms Dynamic programming Searching and Sorting: Number theory… Read More »
Given a number n, check if it is prime or not. We have introduced and discussed School and Fermat methods for primality testing. Primality Test… Read More »
Given a number n, check if it is prime or not. We have introduced and discussed School method for primality testing in Set 1. Primality… Read More »
Given a positive integer, check if the number is prime or not. A prime is a natural number greater than 1 that has no positive… Read More »
Euler’s Totient function Φ(n) for an input n is count of numbers in {1, 2, 3, …, n} that are relatively prime to n, i.e.,… Read More »
Given a positive integer n, find if it can be expressed as xy where y > 1 and x > 0. x and y both… Read More »
Puzzle: You are provided with a chessboard and are asked to find the number of squares in it. A chessboard is a board with 8… Read More »
Given two integers ‘a’ and ‘m’, find modular multiplicative inverse of ‘a’ under modulo ‘m’. The modular multiplicative inverse is an integer ‘x’ such that.… Read More »
Euler’s Totient function ?(n) for an input n is count of numbers in {1, 2, 3, …, n} that are relatively prime to n, i.e.,… Read More »
Given an integer n and a prime number p, find the largest x such that px (p raised to power x) divides n! (factorial) Examples:… Read More »