Wednesday, 1 Dec 2021
Category: number-theory

Given two Geometric Progressions (a1, r1) and (a2, r2) where (x, y) represents GP with initial term x and common ratio y and an integer N, the task is to find the count of the distinct integers that belong to the first N terms of at least one of the given geometric progressions.Examples:Input: N = […]

Given three integers A, B, and C, the task is to find the minimum possible value of |A – X| + |B – Y| + |C – Z| such that X * Y = Z.Example:Input: A = 19, B = 28, C = 522Output: 2Explanation: The most optimal choice of X, Y, and Z for […]

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

Given an integer X, D and T, the task is to check if it is possible to reduce X to 0 in exactly T moves. In each move, X can be reduced by either D or 1. Print YES if possible, else NO.Example:Input: X = 10, D = 3, T = 6Output: YESExplanation: Below are […]

Given a range from L to R and an integer K, the task is to count the number of integers in the given range such that their last K digits are equal.Example: Input: L = 49, R = 101, K=2Output: 6Explanation: There are 6 possible integers t.e., 55, 66, 77, 88, 99 and 100 such that […]

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

Count occurrences of an element in a matrix of size N * N generated such that each element is equal to product of its indices Given two positive integers N and X, the task is to count the occurrences of the given integer X in an N-length square matrix generated such that each element of […]