Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 70 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. package edu.ups.parallel.test;
  2.  
  3. import java.util.Calendar;
  4. import java.util.Random;
  5.  
  6. public class PrimeTest {
  7.     public static void main( String[] args ) {
  8.         PrimeTest pt = new PrimeTest( 1000000 );
  9.     }
  10.     public PrimeTest( long nPrimes ) {
  11.         Calendar start = Calendar.getInstance();
  12.        
  13.         long i = 0;
  14.         boolean[] isPrime = new boolean[ (int) nPrimes ];
  15.         long[] numbers = new long[ (int) nPrimes ];
  16.         parallel for( i = 0; i < nPrimes; i++ ) {
  17.             numbers[ (int) i ] = i;
  18.             isPrime[ (int)i ] = isPrime( i );
  19.         }
  20.        
  21.         Calendar end = Calendar.getInstance();
  22.         System.out.println( end.getTimeInMillis() - start.getTimeInMillis() + " ms");
  23.     }
  24.    
  25.     public boolean isPrime( long p ) {
  26.         long sqrt = (long) Math.sqrt( (double)p );
  27.         for( int k = 2; k < sqrt+1; k++ ) {
  28.             if( p % k == 0 ) {
  29.                 return false;
  30.             }
  31.         }
  32.         return true;
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top