# Tag Archives: Modular Arithmetic

## Smallest number to be added in first Array modulo M to make frequencies of both Arrays equal

Given two arrays A[] and B[] consisting of N positive integers and a integer M, the task is to find the minimum value of X… Read More »

## Count of ways to split given string into two non-empty palindromes

Given a string S, the task is to find the number of ways to split the given string S into two non-empty palindromic strings. Examples:… Read More »

## Generate Array whose sum of all K-size subarrays divided by N leaves remainder X

Given three integer N, K and X, the task is to create an array of length N suach that sum of all its K-length subarrays… Read More »

## Check if the remainder of N-1 factorial when divided by N is N-1 or not

Given an integer N where 1 ≤ N ≤ 105, the task is to find whether (N-1)! % N = N – 1 or not.… Read More »

## Maximize the sum of modulus with every Array element

Given an array A[] consisting of N positive integers, the task is to find the maximum possible value of: F(M) = M % A +… Read More »

## Decrypt the String according to given algorithm

Given an encrypted string str consisting of alphabets and numeric characters, the task is to decrypt the string and find the encrypted message. In order… Read More »

## Modular Arithmetic

Modular arithmetic is the branch of arithmetic mathematics related with the “mod” functionality. Basically, modular arithmetic is related with computation of “mod” of expressions. Expressions… Read More »

## Must do Math for Competitive Programming

Competitive Programming (CP) doesn’t typically require to know high-level calculus or some rocket science. But there are some concepts and tricks which are sufficient most… Read More »

## Quotient Remainder Theorem

Quotient Remainder Theorem states that for any pair of integers a and b (b is positive), there exists two unique integers q and r such… Read More »

Below are some interesting properties of Modular Addition: (a + b) mod m = ((a mod m) + (b mod m)) mod m (a +… Read More »

## Modular Multiplication

Below are some interesting properties of Modular Multiplication (a x b) mod m = ((a mod m) x (b mod m)) mod m (a x… Read More »

## Sort the given stack elements based on their modulo with K

Given a stack of integers and an integer K, the task is to sort the elements of the given stack using another stack in the… Read More »

## Minimum possible value of (i * j) % 2019

Given two integers L and R, the task is to find the minimum possible value of (i * j) % 2019 where L ≤ i… Read More »

## Modulo of a large Binary String

Given a large binary string str and an integer K, the task is to find the value of str % K. Examples: Input: str =… Read More »

## Sort elements by modulo with K

Given an array arr[] of integers and an integer K. The task is to sort the elements of the given array in the increasing order… Read More »