博客
关于我
python学习12:水仙花
阅读量:305 次
发布时间:2019-03-03

本文共 866 字,大约阅读时间需要 2 分钟。

水仙花数验证算法
            '''求101-999中的水仙花数,水仙花数,个十百三数的立方相加等于本身'''                                        def test1():                    for i in range(101, 1000):                        g = i % 10                        s = int(i / 10) % 10                        b = int(i / 100)                        if i == g**3 + s**3 + b**3:                            print(i)                            def test2():                    for i in range(101, 1000):                        st = str(i)                        g = int(st[2])                        s = int(st[1])                        b = int(st[0])                        if i == g**3 + s**3 + b**3:                            print(i)                            test1()                                                    该算法旨在验证水仙花数的数学特性。水仙花数是指一个三位数,其各位数字的立方和等于自身。通过该算法,我们可以快速筛选出满足条件的水仙花数。                    

转载地址:http://fnym.baihongyu.com/

你可能感兴趣的文章
qt调用vs2008编写的dll动态库(隐式调用)
查看>>
Qt读取注册表默认值
查看>>
poj 1679 判断MST是不是唯一的 (次小生成树)
查看>>
POJ 1703 Find them, Catch them
查看>>
POJ 1703 Find them, Catch them 并查集
查看>>
POJ 1738 An old Stone Game(石子合并)
查看>>
POJ 1740 A New Stone Game(博弈)题解
查看>>
Qt网络编程之实例二POST方式
查看>>
POJ 1765 November Rain
查看>>
poj 1860 Currency Exchange
查看>>
POJ 1961 Period
查看>>
POJ 2019 Cornfields (二维RMQ)
查看>>
poj 2057 The Lost House 贪心思想在动态规划上的应用
查看>>
poj 2057 树形DP,数学期望
查看>>
poj 2112 最优挤奶方案
查看>>
Qt编写自定义控件12-进度仪表盘
查看>>
SpringBoot主启动原理在SpringApplication类《第六课》
查看>>
poj 2186 Popular Cows :求能被有多少点是能被所有点到达的点 tarjan O(E)
查看>>
POJ 2186:Popular Cows Tarjan模板题
查看>>
POJ 2229 Sumsets(递推,找规律)
查看>>