zoukankan      html  css  js  c++  java
  • 简单的数字查找

    0. Simple Number Finding

     

    You are playing a card game with your friends. This game in China named “扎金花”. In this game, the

    2, 3, 5 are some simple powerful numbers. Because the combination of 2,3,5 is less than any other combinations but greater than the AAA, which is the king in this game. In today, you want to find if a number is a simple number, in which their factors only include 2, 3 and 5.

    So your task is to find out whether a given number is an amazing number.

    E.g Input: 6

    Output: (2, 3)

    Explanation: 6 = 2 x 3

    Input: 8

    Output: (2, 2, 2)

    Explanation: 8 = 2 x 2 x 2

    Input: 14 Output:None

    Explanation: 14 is not amazing since it includes another prime factor 7.

    How to check your answer:

    If you test 1845281250, your program should give (2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5)

    If you test 3690562500, your program should give (2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5);

    If you test 1230187500, your program should give (2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5); If you test 10023750, your program should give None;

    from math import sqrt, floor
    
    
    def isPrime(number):
        flag = True
        factor = 0
        for i in range(2, floor(sqrt(number)) + 1):
            if number % i == 0:
                flag = False
                factor = i
                break
        return flag, factor
    
    
    if __name__ == "__main__":
        prompt = """请输入一个正整数:"""
        number = int(input(prompt))
        result = []
        while True:
            flag, factor = isPrime(number)
            if flag:
                if number in [2, 3, 5]:
                    result.append(number)
                else:
                    result = []
                break
            else:
                if factor in [2, 3, 5]:
                    result.append(factor)
                    number /= factor
                else:
                    result = []
                    break
        if result:
            print(tuple(result))
        else:
            print(None)
    

      

  • 相关阅读:
    Vue组件别名及Ctrl跳转组件问题
    Scrapy Item Loaders
    scrapy Selector
    NSSM 注册windows服务
    windows 删除注册的服务
    RedisDesktopManager软件窗口不显示
    hexo + Matery主题 + Nginx + 阿里云 搭建个人博客网站
    sublime text3 安装插件
    关于 Windows 10 时间更新
    动画 | 什么是堆排序?
  • 原文地址:https://www.cnblogs.com/keystone/p/10955208.html
Copyright © 2011-2022 走看看