Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. package testforryan;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.*;
  5.  
  6. public class Main {
  7.     //  static int CACHE_SIZE = 100000000;
  8.     //  static byte[] cache;
  9.     public static void main(String[] args) {
  10.         //      int temp;
  11.         //      for (int i = 1; i < 10000000; i++){
  12.         //          temp = i + 1;
  13.         //          temp = i / 2;
  14.         //          temp = i * 3;
  15.         //          temp = i - 4;
  16.         //      }
  17.         Scanner scan = new Scanner(System.in);
  18.         DecimalFormat df = new DecimalFormat();
  19.         System.out.println("input an integer: ");
  20.         double apple = scan.nextDouble();
  21.         ArrayList<Double> primes= new ArrayList<Double>();
  22.         double x = 2;
  23.         double pie = apple;
  24.         double start = System.nanoTime();
  25.         boolean fuckingUseless = false;
  26.         //      cache = new byte[CACHE_SIZE];
  27.         //      for (int z = 0; z < CACHE_SIZE; z++){
  28.         //          cache[z] = -1;
  29.         //      }
  30.         if (isPrime(apple)) {
  31.             System.out.println("Your mother is already prime you sneaky motherfucker...");
  32.             fuckingUseless = true;
  33.             primes.add(apple);
  34.         }
  35.         if (!fuckingUseless){
  36.             do{
  37.                 if (isPrime(x)){
  38.                     if (pie%x == 0){
  39.                         primes.add(x);
  40.                         pie = pie / x;
  41.                         x=2;
  42.                         if (isPrime(pie)) {
  43.                             fuckingUseless = true;
  44.                             primes.add(pie);
  45.                             break;
  46.                         }
  47.                     }
  48.                     else {
  49.                         x++;
  50.                     }
  51.                 }
  52.                 else {
  53.                     x++;
  54.                 }
  55.             } while(x<=Math.sqrt(pie));
  56.             primes.add(pie);
  57.         }
  58.  
  59.         double total = System.nanoTime() - start;
  60.         System.out.println("The total time is:\t" + total/1000000000);
  61.         System.out.println("the prime roots are: ");
  62.         for (double z : primes){
  63.             System.out.print(df.format(z)+ " ");
  64.         }
  65.     }
  66.  
  67.     public static boolean isPrime(double x){
  68.         boolean bool = true;
  69.         boolean cacheable = false;
  70.         //      if (x < CACHE_SIZE) {
  71.         //          cacheable = true;
  72.         //          if (cache[(int) x] != -1){
  73.         //              return cache[(int) x] == 0 ? true : false;
  74.         //          }
  75.         //
  76.         //      if (x == 2) {
  77.         //          if (cacheable) cache[2] = 0;
  78.         //          return true;
  79.         //      }
  80.         //      }      
  81.         if (x % 2 == 0) {
  82.             //          if (cacheable) cache[(int)x] = 1;
  83.             return false;
  84.         }
  85.         for (double y = 3; y < Math.sqrt(x) + 1; y += 2){
  86.             if (x%y == 0){
  87.                 //              if (cacheable) cache[(int)x] = 1;
  88.                 bool = false;
  89.                 break;
  90.             }
  91.         }
  92.         //      if (bool && cacheable) cache[(int)x] = 0;
  93.         return bool;
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement