|
Post by Admin on Jun 3, 2013 19:32:01 GMT
Duke i renditur numrat e thjeshte 2,3,5,7,11,13,shohim se 13 eshte numri i 6sht i thjeshte. Cili eshte numri i 10001 i thjeshte?
|
|
|
Post by arja on Jun 4, 2013 12:29:18 GMT
public class nrithjeshte { <span style="font-family: Verdana, Arial; font-size: 10pt;">public static void main(String args[]) {</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">int[] primes = new int[10002];</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">int tmp = 0;</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">for ( int i = 2; i < 10000000; i++ ) { </span> <span style="font-family: Verdana, Arial; font-size: 10pt;">int j = 0; </span> <span style="font-family: Verdana, Arial; font-size: 10pt;">while ( j < 10002 ) {</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">if ( isPrime(i) && i > tmp ) {</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">primes[j] = i;</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">tmp = i;</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">j++;</span><span style="font-family: Verdana, Arial; font-size: 10pt;">}</span> break;}} System.out.println(primes[10001]); <span style="font-family: Verdana, Arial; font-size: 10pt;">}</span>
public static boolean isPrime( int x ) { for ( int i = 2; i <= x / 2; i++ ) { if ( x % i == 0 ) { return false; }<span style="font-family: Verdana, Arial; font-size: 10pt;">}</span> <span style="font-family: Verdana, Arial; font-size: 10pt;">return true; </span> <span style="font-family: Verdana, Arial; font-size: 10pt;">}</span>}
|
|