The machine test of prime number factor

Source: Internet
Author: User

Function: Enter a positive integer that outputs all of its prime number factors (such as 180 prime number factor 2 2 3 3 5) in a small to large order

Detailed Description:


Function Interface Description:

Public String GetResult (long Uldatainput)

Input parameters:

Long uldatainput: A positive integer entered

return value:

String


Enter a description:

Enter a long integer

Output Description:

A factor that outputs all of its prime numbers in a small to large order, separated by a space
Enter an example:

180

Output Example:
2 2 3 3 5
The idea: The breakthrough is to divide the long number by the time it starts at 2 and then loops. Until this long type ==1
The code is as follows:
Import Java.util.Scanner;

public class Hua_6 {public
   static void Main (string[] args) {
	   Scanner sc =new Scanner (system.in);
	   Long x =sc.nextlong ();
	   GetResult (x);
   }
   static void GetResult (long x) {
	       int i=0;
	       int k= (int) x;
	       while (true) {for
	    	   (i=2;i<=k;i++) {
	    		   if (k%i==0) {
	    			    System.out.print (i+ "");
	    			    k=k/i;
	    			    break;
	    		   } 
	    	   }
	    	   if (k==1) {break;}}}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.