Given an integer N, your task is to count the minimum number of operations required to make N a perfect square. In each operation you can either subtract from or add to N by 2. i.e you can wither replace N by N + 2 or by N - 2.
Answers
Answered by
0
Given : In each operation you can either subtract from or add to N by 2. i.e you can wither replace N by N + 2 or by N - 2.
To Find : minimum number of operations required make N a perfect square.
Solution:
Start
Input Number = N ( Integer)
A = N
if A is prefect Square
{
Count
C1 = (A - N)/2
}
Else
{
A = A + 2
Go To if A is prefect Square
}
S = N-2
if S is prefect Square
{
Count
C2 = (N-S)/2
}
Else
{
S = S - 2
Go To if S is prefect Square
}
if ( C1 ≤ C2)
{ Print Count = C1 }
Else
{ Print Count = C2 }
End
Learn More:
Write a a algorithm for a program that adds two digits numbers ...
https://brainly.in/question/14599411
Draw a flow chart and write an algorithm for a program that adds all ...
https://brainly.in/question/12819501
Similar questions