有意思的面试题 Simple Number Finding

本文介绍了一种名为“扎金花”的中国纸牌游戏中神奇数的概念,即仅由2、3、5这三个质数组成的数。通过分析和算法实现,我们探讨了如何判断一个数是否为神奇数,并提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 3Input: 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

import numpy as np

divNum = np.array([1, 2, 3, 5], dtype=int)
numList = []


def main():
    ################### At here input your number################
    inputNum = 1845281250
    ################### At here input your number################

    while True:
        if inputNum % 2 == 0:
            inputNum = inputNum / 2
            numList.append(2)
        elif inputNum % 3 == 0:
            inputNum = inputNum / 3
            numList.append(3)
        elif inputNum % 5 == 0:
            inputNum = inputNum / 5
            numList.append(5)
        else:
            if (divNum == inputNum).any():
                if inputNum != 1:
                    numList.append(inputNum)
                print(numList)
            else:
                print('None')
            break;


if __name__ == '__main__':
    main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值