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)
    

      

  • 相关阅读:
    油猴脚本
    js hook
    js控制台原理检测
    安卓so文件函数动态注册
    js一些简单逆向题目实战
    js基础补充落下的知识点
    js反爬原理
    js容易让人眼瞎的写法
    js基础
    js一些常见非指纹built-in函数
  • 原文地址:https://www.cnblogs.com/keystone/p/10955208.html
Copyright © 2011-2022 走看看