Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 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(!fuckingUseless);
  56.         }
  57.  
  58.         double total = System.nanoTime() - start;
  59.         System.out.println("The total time is:\t" + total/1000000000);
  60.         System.out.println("the prime roots are: ");
  61.         for (double z : primes){
  62.             System.out.print(df.format(z)+ " ");
  63.         }
  64.     }
  65.  
  66.     public static boolean isPrime(double x){
  67.         boolean bool = true;
  68.         boolean cacheable = false;
  69.         //      if (x < CACHE_SIZE) {
  70.         //          cacheable = true;
  71.         //          if (cache[(int) x] != -1){
  72.         //              return cache[(int) x] == 0 ? true : false;
  73.         //          }
  74.         //
  75.         //      if (x == 2) {
  76.         //          if (cacheable) cache[2] = 0;
  77.         //          return true;
  78.         //      }
  79.         //      }      
  80.         if (x % 2 == 0) {
  81.             //          if (cacheable) cache[(int)x] = 1;
  82.             return false;
  83.         }
  84.         for (double y = 3; y < Math.sqrt(x) + 1; y += 2){
  85.             if (x%y == 0){
  86.                 //              if (cacheable) cache[(int)x] = 1;
  87.                 bool = false;
  88.                 break;
  89.             }
  90.         }
  91.         //      if (bool && cacheable) cache[(int)x] = 0;
  92.         return bool;
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement