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)
    

      

  • 相关阅读:
    Centos7 ifconfig命令找不到
    request的各种方法
    linux开放端口
    easyui datagrid 部分参数
    设置tomcat内存
    tomcat做成系统服务
    Meta-analysis with complex research designs: dealing with dependence from multiple measures and multiple group comparisons
    多重校正
    DTI
    learning source archive
  • 原文地址:https://www.cnblogs.com/keystone/p/10955208.html
Copyright © 2011-2022 走看看