Tag Archives: number-theory

Optimized Euler Totient Function for Multiple EvaluationsJune 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 »

Smallest number S such that N is a factor of S factorial or S!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 »

Check if a number can be written as a sum of ‘k’ prime numbersJune 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 »

Sum of divisors of factorial of a numberJune 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 »

Primality Test | Set 4 (Solovay-Strassen)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 »

Compute nCr % p | Set 3 (Using Fermat Little Theorem)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 »

Modulo 10^9+7 (1000000007)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 »

RSA Algorithm in CryptographyApril 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 »

number-theoryGenerators of finite cyclic group under additionMarch 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 »

Find power of power under mod of a primeFebruary 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 »

GFact 22 | (2^x + 1 and Prime)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 »

How to prepare for ACM – ICPC?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 »