##
Optimized Euler Totient Function for Multiple Evaluations
June 26, 2017

Euler Totient Function (ETF) Φ(n) for an input n is count of numbers in {1, 2, 3, …, n} that are relatively prime to n,… Read More »

June 26, 2017

Euler Totient Function (ETF) Φ(n) for an input n is count of numbers in {1, 2, 3, …, n} that are relatively prime to n,… Read More »

June 20, 2017

Given a number N. You are tasked with finding the smallest number S, such that N is a factor of S! (S factorial). N can… Read More »

June 19, 2017

Given two numbers N and K. We need to find out if ‘N’ can be written as sum of ‘K’ prime numbers. Given N <=… Read More »

June 7, 2017

Given a number n, we need to calculate the sum of divisors of factorial of the number. Examples: Input : 4 Output : 60 Factorial… Read More »

May 22, 2017

We have already been introduced to primality testing in the previous articles in this series. Primality Test | Set 1 (Introduction and School Method) Primality… Read More »

May 4, 2017

Given three numbers n, r and p, compute value of nCr mod p. Here p is a prime number greater than n. Here nCr is… Read More »

April 29, 2017

In most of the programming competitions, problems are required to answer the result in 10^9+7 modulo. The reason behind this is to have problems for… Read More »

April 22, 2017

RSA algorithm is asymmetric cryptography algorithm. Asymmetric actually means that it works on two different keys i.e. Public Key and Private Key. As the name… Read More »

March 21, 2017

Given a number n, find all generators of cyclic additive group under modulo n. Generator of a set {0, 1, … n-1} is an element… Read More »

February 22, 2017

Given four numbers A, B, C and M, where M is prime number. Our task is to find ABC (mod M). Input : A =… Read More »

November 11, 2016

A number of the form 2x + 1 (where x > 0) is prime if and only if x is a power of 2, i.e.,… Read More »

October 4, 2016

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 »

September 27, 2016

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 »

January 3, 2016

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 »

December 16, 2015

Given a large number n and a prime p, how to efficiently compute n! % p? Examples: Input: n = 5, p = 13 Output:… Read More »