Category: number-theory

Find a prime number S containing given number N in it

Given an integer N, find a prime number S such that all digits of N occur in a contiguous sequence. There may be multiple answers. Print any one of them.Example:Input: N = 42Output: 42013Explanation: 42013 is a prime and 42 occurs as a contiguous number in it. 15427 is also a correct answer.Input: N = […]

Continue Reading

Solve Linear Congruences Ax = B (mod N) for values of x in range [0, N-1]

#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 […]

Continue Reading