Monday, 29 Nov 2021
Category: Modular Arithmetic

#include using namespace std;  string changeNtoM(int N, int M){        if (N == M) {        return ” “;    }          if (M == 0) {        return “-“;    }          queue q;          unordered_map visited;          q.push({ N, “” }), visited[N] = 1;          q.push({ 1, “/” }), visited = 1;          while (!q.empty()) {                pair cur = q.front();        q.pop();                                  if (cur.first == M) {                        return cur.second;        }                          if (!visited[cur.first + cur.first]            && cur.first + cur.first

Given three integers A, N and P, the task is to find (A^(N!)) % P.Examples:Input: A = 2, N = 1, P = 2Output: 0Explanation: As (2^(1!)) = 2Therefore 2 % 2 will be 0.Input: A = 3, N = 3, P = 2Output: 1Naive Approach: The simplest solution of this problem can be find […]

#include using namespace std;  long long ExtendedEuclidAlgo(    long long a, long long b,    long long& x, long long& y){        if (b == 0) {        x = 1;        y = 0;        return a;    }    else {                  long long x1, y1;        long long gcd            = ExtendedEuclidAlgo(b, a % b, x1, y1);                          x = y1;        y = x1 – floor(a / b) * y1;          return gcd;    }}  void linearCongruence(long long A,                      long long B,                      long long N){    A […]

Number of relations that are neither Reflexive nor Irreflexive on a SetGiven a positive intege N, the task is to find the number of relations that are neither reflexive nor irreflexive on a set of first N natural numbers. Since the count of relations can be very large, print it to modulo 109 + 7.A […]

In programming, the modulo operation gives the remainder or signed remainder of a division, after one integer is divided by another integer. It is one of the most used operators in programming. This article discusses when and why the modulo operation yields a negative result. Examples: In C, 3 % 2 returns 1. However, -3 […]

Count distinct ways to replace array elements such that product of the array becomes even Given an array arr[] consisting of N odd integers, the task is to count the different number of ways to make the product of all array elements even, by repeatedly changing any set of elements to any values. Since the […]