Lintcode Python Simple Class topic 517. Number of ugly

Source: Internet
Author: User

Title Description:

Write a program to detect if an integer is not 丑数 .

An ugly number is defined as a positive integer that contains only the mass factor 2, 3, 5 . For example, 6, 8 is the ugly number, but 14 is not ugly number thought he contains a quality factor 7.

Precautions

Can be thought of 1 as a special ugly number.

Have you ever encountered this problem in a real interview? Yes Sample Example

Given num = 8 , return true .
Given num = 14 , return false .

labelMathematical

Topic Analysis:

The remainder of the 2/3/5 is recycled and the quotient can be taken. Yu = 0, the quotient of =1 when the number of ugly.

Source:

Class solution:    # @param {int} num an integer    # @return {Boolean} true if Num was an ugly number or false    def I sugly (self, num):        # Write Your code here        if num = = 1:return True        if num = = 0:return False        t = [2,3,5]
   i = 0 while        True:            If i = = 3:                 return False            res = num%t[i]            cor = num/t[i]             if Cor = = 1 and re s = = 0:                return True            elif res = = 0:                 num = num/t[i]                continue            Else:                i + = 1

Lintcode Python Simple Class topic 517. Number of ugly

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.