Python3 decomposition factorization

Source: Internet
Author: User

Python3 decomposition factorization

#!/usr/bin/env python#-*-coding:utf-8-*-# Author:hiuhung wannum = Int (input ("Please enter a composite:")) n = Numlist1 = []  #存放质因数for J in range (int (N/2) +1): For    I in range (2,n):        if num% i = = 0:  #可以整除            list1.append (i)            num = num//i
   breakif len (list1) = = 0:    print ("This number is prime, please reenter another number")    exit () #print (list1) print ('%d = '% (n), end= ') for I in Range (len (list1)):    if I  = = Len (list1)-1:        print ('%s '% (List1[i]))    else:        print ('%s * '% (list1 [i]), end= ")

Effect:

C:\Python36\python.exe d:/py/1704/day03/decomposition factorization. Py Please enter a composite: 1574115741 = 3 * 3 * 3 * one * 53Process finished with exit code 0

  

Python3 decomposition factorization

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.