#简单
def narcissus():
for n in range(100, 1000, 1):
a, b, c = n//100, (n//10)%10, (n%100)%10
if a ** 3 + b ** 3 + c ** 3 == n:
print(n) #使用yield写法
def narcissus_yield():
m, n = 100, 999
while m <= n:
a, b, c = m // 100, (m // 10) % 10, (m % 100) % 10
if a ** 3 + b ** 3 + c ** 3 == m:
yield m
m = m + 1 #包含水仙花等。。。
def narcissus_all(min, max):
if type(min) != int or type(max) != int:
msg = "参数类型必须为int"
raise TypeError(msg)
if min is None or max is None:
msg = "参数值不能为None!!!"
raise ValueError(msg)
if max == 0 or max < min:
msg = "max不能为0或者max必须比min值大"
raise ValueError(msg)
length = len(str(max))
while min <= max:
temp_val, sum = min, 0
for n in range(length):
sum += (temp_val%10) ** length
temp_val //= 10
if min == sum:
yield min
min = min + 1 for n in narcissus_all(100000, 999999):
print(n)

最新文章

  1. MySQL8:连接查询
  2. mysql 连接慢的问题(超过了1秒)
  3. 318. Maximum Product of Word Lengths
  4. 理解 OpenStack + Ceph (2):Ceph 的物理和逻辑结构 [Ceph Architecture]
  5. ffmpeg-20160726-bin.7z
  6. Reading and Writing CSV Files in C#
  7. git 常用
  8. 每日英语:A Whiff Of &#39;Welcome Home&#39;
  9. PostgreSQL Replication之第十二章 与Postgres-XC一起工作(1)
  10. 分分钟知道tiles框架是干嘛的
  11. javascript--自己用的插件
  12. 基于visual Studio2013解决算法导论之017查找第n小元素
  13. Oracle 11g sys,system 密码忘记设置解决办法
  14. Spring Boot 整合 Mybatis 实现 Druid 多数据源详解
  15. 5.For loops
  16. tensorflow-TFRecord报错ValueError: Protocol message Feature has no &quot;feature&quot; field.
  17. SQL Server中如何定位Row Lock锁定哪一行数据
  18. vue-cli笔记
  19. python导出数据到excel
  20. 2018.08.28 集合堆栈机(模拟+STL)

热门文章

  1. 安装最新版的wampserver,可以兼容php5和php7
  2. 自动化构建工具grunt的学习
  3. Kettle api 二次开发之 日志的保存
  4. 截屏快捷键(windows)自带截屏,不需要安装任何插件
  5. 【oracle】关于创建表时用default指定默认值的坑
  6. HDU Ellipse(simpson积分)
  7. hdu_5187_zhx&#39;s contest
  8. 对DataSet,DataRow,DateTable转换成相应的模型
  9. 关于windows下安装mysql数据库出现中文乱码的问题
  10. 详解PreparedStatement