Lowest Factor

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Java

Create a method that finds the factor of a number with the lowest magnitude that is not 1 for composite numbers, and 1 for prime numbers.

Methods

Your program should define and implement the following methods:

A getLowestFactor method that takes the following parameters:
  • An int representing the number whose lowest factor should be found.

The method should return an int representing the lowest factor of the parameter. If the parameter is prime, return 1. Otherwise return the lowest factor that is not 1.

Input Specification

The input is a single integer n (2 \le n \le 10^6) representing the number that needs to have its lowest factor found.

Output Specification

Create and call the method outlined above in order to find the lowest factor of the number, then print it.

Sample Input

12

Sample Output

2

Comments

There are no comments at the moment.