One Time Password Difficulty: easy Max Points: 10 Description 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
One Time Password
Difficulty: easy
Max Points: 10
Description
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 the sum of the largest and smallest prime numbers 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.
Public Test Cases
# Input Expected Output
1 -97 50 50
Programming Language: C (GCC 9.2.0)
#include<stdio.h>
int main()
{
long long int x,y,t;
scanf("%lld %lld",&x,&y);
if(x>y)
{
t=x;
x=y;
y=t;
}
long long int i,maxp,minp;
while(1)
{
if(x<0)
t=-x;
else
t=x;
for(i=2;i<=t/2;i++)
{
if(t%i==0)
break;
}
if(i>t/2)
{
minp=x;
break;
}
x++;
}
while(1)
{
if(y<0)
t=-y;
else
t=y;
for(i=2;i<=t/2;i++)
{
if(t%i==0)
break;
}
if(i>t/2)
{
maxp=y;
break;
}
y--;
}
printf("%lld", maxp+minp);
return 0;
}
Comments
Post a Comment