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)
    

      

  • 相关阅读:
    qemu进程页表和EPT的同步问题
    Linux进程虚拟地址空间管理2
    qemu-kvm内存虚拟化1
    LInux进程虚拟地址空间的管理
    Linux下的文件系统2
    LInux中的文件系统1
    Linux IPC之管道通信
    操作系统中的特权级检查
    Linux下的信号机制
    进程的挂起、阻塞和睡眠
  • 原文地址:https://www.cnblogs.com/keystone/p/10955208.html
Copyright © 2011-2022 走看看