factorization

Finding largest prime number out of 600851475143?

会有一股神秘感。 提交于 2019-11-26 15:32:59
I'm trying to solve problem 3 from http://projecteuler.net . However, when I run thing program nothing prints out. What am I doing wrong? Problem: What is the largest prime factor of the number 600851475143 ? public class project_3 { public boolean prime(long x) // if x is prime return true { boolean bool = false; for(long count=1L; count<x; count++) { if( x%count==0 ) { bool = false; break; } else { bool = true; } } return bool; } public static void main(String[] args) { long ultprime = 0L; // largest prime value project_3 object = new project_3(); for(long x=1L; x <= 600851475143L; x++) { if

Java Display the Prime Factorization of a number

喜夏-厌秋 提交于 2019-11-26 11:31:08
问题 So for my assignment, I have to write a program that asks the user for an integer input and then print out that number\'s prime factorization. This is what I have: import java.util.Scanner; public class PrimeFactor { public static void main(String[] args) { System.out.print(\"Enter a positive number: \"); Scanner scanner = new Scanner (System.in); int number = scanner.nextInt(); int count; for (int i = 2; i<=(number); i++) { count = 0; while (number % i == 0) { number /= i; count++; if (count