Taddeus Kroes 10 năm trước cách đây
mục cha
commit
b5d097ae36
1 tập tin đã thay đổi với 28 bổ sung0 xóa
  1. 28 0
      55.py

+ 28 - 0
55.py

@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+def rev(n):
+    r = 0
+    base = 1
+
+    while n > 0:
+        div, rem = divmod(n, 10)
+        r = r * 10 + rem
+        base *= 10
+        n = div
+
+    return r
+
+def is_lychrel(n):
+    niter = 0
+
+    while niter < 50:
+        n += rev(n)
+
+        if rev(n) == n:
+            return False
+
+        niter += 1
+
+    return True
+
+print sum(int(is_lychrel(n)) for n in xrange(1, 10000))