Sunday, 28 November 2021

Maximum GCD Problem !!!

 PROBLEM 21: Maximum GCD


Problem Reference : Codeforces 

Let's consider all integers in the range from 1 to n (inclusive).

Among all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of gcd(a,b), where 1a<bn.

The greatest common divisor, gcd(a,b), of two positive integers a and b is the biggest integer that is a divisor of both a and b.


Input:

The first line contains a single integer t (1t100)  — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single integer n (2n106).


Output:

For each test case, output the maximum value of gcd(a,b) among all 1a<bn.


Solution: 


  1. t = int(input())
  2. i = 0
  3. while i < t:
  4. n = int(input())
  5. n1 = n // 2
  6. print(n1)
  7. i += 1


The above solution is in python language.



Example
input
2
3
5
output
1
2

No comments:

Post a Comment

Rearrange an array with O(1) extra space

  PROBLEM 61:  Rearrange an array with O(1) extra space (For best view experience, view in windows version) Problem Reference : GeeksForGeek...