Wipro NLTH Coding Solve | One Time Password | Codewindow.in

An e-commerce site wishes to enhance its ordering process. They plan to implement a new scheme of OTP (One Time Password) generation for order confirmations. The OTP can be any number of digits. For OTP generation, the user will be asked to enter two random numbers. The first number entered should always be smaller than the second number. The OTP is calculated as the sum of the maximum and the minimum prime values in the range of the user-entered numbers. Write an algorithm to find the OTP.

Input
The input consists of two space-separated integers – firstNumber and secondNumber, representing the two numbers entered by the user. Both numbers are considered in the range.

Output
Print an integer representing sum of largest and smallest prime number in the range of given numbers.

Constraints
-109< firstNumber <secondNumbers<109

Example

Input:
-97 50

Output:
50

Explanation
The smallest and largest prime numbers within the given numbers are -97 and 47, respectively. The sum of -97 and 47 is 50. So, the output is 50.

Solution: In C

#include
int main()
{
    long long int x,y,t;
    scanf("%lld %lld",&amp;x,&amp;y);
    if(x&gt;y)
    {
        t=x;
        x=y;
        y=t;
    }
    long long int i,maxp,minp;
    while(1)
    {
        if(x&lt;0)
            t=-x;
        else
            t=x;
        for(i=2;it/2)
        {
            minp=x;
            break;
        }
        x++;
    }
    while(1)
    {
        if(y&lt;0)
            t=-y;
        else
            t=y;
        for(i=2;it/2)
        {
            maxp=y;
            break;
        }
        y--;
    }
    printf("%lld", maxp+minp);
    return 0;
}

Also Checkout

Recent Posts

Leave a Comment

Your email address will not be published. Required fields are marked *