Created
October 7, 2012 10:56
-
-
Save jpustula/3847856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implementacja funkcji pi(n). | |
* Oblicza liczbę liczb pierwszych z zadanego przedziału | |
* | |
* @param int n Liczba naturalna | |
*/ | |
public static int pi(int n) { | |
/** | |
* Liczba liczb pierwszych z zadanego przedziału. | |
* Wartość początkowa pochodzi z zadanego wzoru. | |
*/ | |
int total_prime_numbers = -1; | |
for (int j = 3; j <= n; j++) { | |
total_prime_numbers += factorial(j - 2) - j * Math.floor(factorial(j - 2) / j); | |
} | |
return total_prime_numbers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment