Skip to content

Instantly share code, notes, and snippets.

@debaimade
Created October 4, 2016 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debaimade/1be73d485b3e180e11be88d3d6f1650b to your computer and use it in GitHub Desktop.
Save debaimade/1be73d485b3e180e11be88d3d6f1650b to your computer and use it in GitHub Desktop.
Returns the number from which a factorial was evaluated
import java.util.Scanner;
public class ReverseFactorial {
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
int check = number;
int result = 2;
boolean isFactorial = false;
while (check >= 1) {
if (check % result == 0) {
check = check / result;
if (check == 1) {
isFactorial = true;
break;
}
} else {
isFactorial = false;
break;
}
result++;
}
if (isFactorial) {
System.out.println(number + " " + result + "!");
} else {
System.out.println(number + " NONE");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment