Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
38
Task/Factorial-primes/Java/factorial-primes-1.java
Normal file
38
Task/Factorial-primes/Java/factorial-primes-1.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
public class MainApp {
|
||||
public static void main(String[] args) {
|
||||
int countOfPrimes = 0;
|
||||
final int targetCountOfPrimes = 10;
|
||||
long f = 1;
|
||||
while (countOfPrimes < targetCountOfPrimes) {
|
||||
long factorialNum = getFactorial(f);
|
||||
boolean primePlus = isPrime(factorialNum + 1);
|
||||
boolean primeMinus = isPrime(factorialNum - 1);
|
||||
if (primeMinus) {
|
||||
countOfPrimes++;
|
||||
System.out.println(countOfPrimes + ": " + factorialNum + "! - 1 = " + (factorialNum - 1));
|
||||
|
||||
}
|
||||
if (primePlus && f > 1) {
|
||||
countOfPrimes++;
|
||||
System.out.println(countOfPrimes + ": " + factorialNum + "! + 1 = " + (factorialNum + 1));
|
||||
}
|
||||
f++;
|
||||
}
|
||||
}
|
||||
|
||||
private static long getFactorial(long f) {
|
||||
long factorial = 1;
|
||||
for (long i = 1; i < f; i++) {
|
||||
factorial *= i;
|
||||
}
|
||||
return factorial;
|
||||
}
|
||||
|
||||
private static boolean isPrime(long num) {
|
||||
if (num < 2) {return false;}
|
||||
for (long i = 2; i < num; i++) {
|
||||
if (num % i == 0) {return false;}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue