# Tag Archives: number-theory

## RSA Algorithm in Cryptography

filter_none edit close play_arrow link brightness_4 code # Write Python3 code here from decimal import Decimal    def gcd(a,b):     if b==0:         return a     else:         return… Read More »

## Number Theory | Generators of finite cyclic group under addition

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 »

## Program for Goldbach’s Conjecture (Two Primes with given Sum)

Goldbach’s conjecture is one of the oldest and best-known unsolved problems in number theory of mathematics. Every even integer greater than 2 can be expressed… Read More »

## Find power of power under mod of a prime

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

## GFact 22 | (2^x + 1 and Prime)

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 »

## Common Divisors of Two Numbers

Given two integer numbers, the task is to find count of all common divisors of given numbers? Examples : Input : a = 12, b… Read More »

## Sum of all proper divisors of a natural number

Given a natural number, calculate sum of all its proper divisors. A proper divisor of a natural number is the divisor that is strictly less… Read More »

## 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 »

## How to prepare for ACM – ICPC?

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 »

## Carmichael Numbers

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 »

## Pollard’s Rho Algorithm for Prime Factorization

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 »

## Compute n! under modulo p

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

## Top 10 Algorithms and Data Structures for Competitive Programming

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 »

## Primality Test | Set 3 (Miller–Rabin)

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 »

## Primality Test | Set 2 (Fermat Method)

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 »