ou are given two positive integers X and K. We define LCM(i,j) for two positive integers i and j as the minimum positive integer y such that both i and j divide y without remainder.

 

You are given two positive integers X and K.  You have to output the minimum and maximum value of LCM(i,j) where X≤i<j≤X⋅K.  We define LCM(i,j) for two positive integers i and j as the minimum positive integer y such that both i and j divide y without remainder.






OURSHOPKEEPER

















#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int t;
  scanf("%d",&t);
  while (t--)
  {
    int x, k, i, j, n, d = 0;
    scanf("%d", &x);
    scanf("%d", &k);

    k = k * x;
    i = x;
    j = k;
    n = j - i;

    int u[n + 1];
    for (int p = i; p <= j; p++)
    {
      u[d] = p;
      ++d;
    }

    int m = (n + 1) * (n + 1) / 2;

    int r[m];
    int count = 0;

    for (int d = 0; d <= n; d++)
    {
      for (int e = d + 1; e <= n; e++)
      {
        int pew = (u[d] * u[e]) / __gcd(u[d], u[e]);
        r[count] = pew;
        count++;
      }
    }

    int min = r[0];
    int max = r[1];
    for (int i = 0; i < count; i++)
    {
      if (min >= r[i])
        min = r[i];
      else if (max < r[i])
      {
        max = r[i];
      }
    }
   // cout<<min;
   // cout<<max;
    printf("%d",min," ");
    printf(" %d\n",max," ");
  }
}







    


Click on the above button to download the code.



Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post