![]() |
Given a positive integer N. In one operation subtract N with its highest divisor other than N and 1. The task is to find minimum operations required to reduce N exactly to a prime number. Examples:
Approach: This problem can be solved by using simple concepts of maths. Follow the steps below to solve the given problem.
Below is the implementation of the above approach: C++
Java
Python3
C#
Javascript
Output
1
Time Complexity: O(sqrtN)
Auxiliary Space: O(1)
|
Reffered: https://www.geeksforgeeks.org
Mathematical |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |