# NCG - Editorial

Practice

Editorialist: akshayakgec

EASY

Basic and gcd

# PROBLEM:

om has an important test to take, the test involves computing GCD. Tom remembers that he has been taught how to compute GCD of two numbers but this test seems to be somewhat different, so he needs your help.
The problem statement is as follows:
You are given two numbers L and R . Your task is to compute the gcd of numbers in range [L, R] (both inclusive). More formally you need to find GCD(L, L+1, L+2, L+3, … R) .

# QUICK EXPLANATION:

As we know that the gcd of two consecutive number is so if l != r we will print 1 and if l == r we will print l.

# EXPLANATION:

If L and R are equal then their gcd will be equal i.e. L or R.

In all other cases, the answer will be 1 because if we take gcd of any two consecutive numbers it will be 1 and gcd of any number with 1 is 1. Two consecutive numbers are always coprime and gcd of coprime numbers is always 1.

Editorialist's Solution
``````#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
int t; cin >> t;
while(t--) {
string l, r, ans;
cin >> l >> r;
if(l == r)
{
ans = l;
}
else
{
ans = "1";
}
cout << ans << "\n";
}
return 0;
}
``````