Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testforryan;
- import java.text.DecimalFormat;
- import java.util.*;
- public class Main {
- // static int CACHE_SIZE = 100000000;
- // static byte[] cache;
- public static void main(String[] args) {
- // int temp;
- // for (int i = 1; i < 10000000; i++){
- // temp = i + 1;
- // temp = i / 2;
- // temp = i * 3;
- // temp = i - 4;
- // }
- Scanner scan = new Scanner(System.in);
- DecimalFormat df = new DecimalFormat();
- System.out.println("input an integer: ");
- double apple = scan.nextDouble();
- ArrayList<Double> primes= new ArrayList<Double>();
- double x = 2;
- double pie = apple;
- double start = System.nanoTime();
- boolean fuckingUseless = false;
- // cache = new byte[CACHE_SIZE];
- // for (int z = 0; z < CACHE_SIZE; z++){
- // cache[z] = -1;
- // }
- if (isPrime(apple)) {
- System.out.println("Your mother is already prime you sneaky motherfucker...");
- fuckingUseless = true;
- primes.add(apple);
- }
- if (!fuckingUseless){
- do{
- if (isPrime(x)){
- if (pie%x == 0){
- primes.add(x);
- pie = pie / x;
- x=2;
- if (isPrime(pie)) {
- fuckingUseless = true;
- primes.add(pie);
- break;
- }
- }
- else {
- x++;
- }
- }
- else {
- x++;
- }
- } while(!fuckingUseless);
- }
- double total = System.nanoTime() - start;
- System.out.println("The total time is:\t" + total/1000000000);
- System.out.println("the prime roots are: ");
- for (double z : primes){
- System.out.print(df.format(z)+ " ");
- }
- }
- public static boolean isPrime(double x){
- boolean bool = true;
- boolean cacheable = false;
- // if (x < CACHE_SIZE) {
- // cacheable = true;
- // if (cache[(int) x] != -1){
- // return cache[(int) x] == 0 ? true : false;
- // }
- //
- // if (x == 2) {
- // if (cacheable) cache[2] = 0;
- // return true;
- // }
- // }
- if (x % 2 == 0) {
- // if (cacheable) cache[(int)x] = 1;
- return false;
- }
- for (double y = 3; y < Math.sqrt(x) + 1; y += 2){
- if (x%y == 0){
- // if (cacheable) cache[(int)x] = 1;
- bool = false;
- break;
- }
- }
- // if (bool && cacheable) cache[(int)x] = 0;
- return bool;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement