Huawei machine test-prime factor

Source: Internet
Author: User

According to the basic theorem of arithmetic, each integer greater than 1 is either a prime number or a product of a series of prime numbers.

Importjava.util.ArrayList;Importjava.util.Arrays;Importjava.util.List;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); Long N=Scanner.nextlong ();        SYSTEM.OUT.PRINTLN (CONVERT (n));    Scanner.close (); }      Public StaticString Convert (Long N) {List<Long> list=NewArraylist<long>(); Long Temp=N;  for(Longi=2;i<=temp/2;i++)        {            if(Isprimarynum (i)) { while(n%i==0) {list.add (i); N=n/i; }                if(n==1)                     Break; }} String restr="";  for(intI=0;i<list.size (); i++) Restr+=list.get (i) + ""; returnRestr.trim (); }         Public Static BooleanIsprimarynum (LongN) {if(n<=1)            return false; if(n==2| | N==3)            return true; Doublesq=math.sqrt (n); if(n%2==0)            return false;  for(inti=3;i<=sq;i+=2)        {            if(n%i==0)                return false; }        return true; }}

Huawei machine test-prime factor

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.