Project Euler 92

2024-06-14 15:58
文章标签 92 project euler

本文主要是介绍Project Euler 92,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Square digit chains

Problem 92

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.

For example,

44 → 32 → 13 → 10 → 1 → 1
85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89

Therefore any chain that arrives at 1 or 89 will become stuck in an endless loop. What is most amazing is that EVERY starting number will eventually arrive at 1 or 89.

How many starting numbers below ten million will arrive at 89?


0.57s,重复组合数什么的。(F 的 120s 真的太彪悍了。)

import itertools
import timedef conquer():ans = 0DIGIT_LIMIT = 7ITER_STR = "0123456789"sum_square = lambda ss: sum( int( s ) ** 2 for s in str( ss ) )fact = lambda num: reduce( lambda x, y: x * y, xrange( 1, num + 1 ) )combinations = itertools.combinations_with_replacement( ITER_STR, DIGIT_LIMIT )def combinatorial_num( num ):res = fact( DIGIT_LIMIT )s = str( num )for ss in ITER_STR:count = s.count( ss )if count > 1: res /= fact( count )return resfor c in combinations:num = int( "".join( c ) )if num == 0: continuewhile num != 89 and num != 1:num = sum_square( num )if num == 89:ans += combinatorial_num( c )print ansbegin = time.time()
conquer()
end = time.time()
print end - begin


这篇关于Project Euler 92的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1060856

相关文章

Debugging Lua Project created in Cocos Code IDE creates “Waiting for debugger to connect” in Win-7

转自 I Installed Cocos Code IDE and created a new Lua Project. When Debugging the Project(F11) the game window pops up and gives me the message waiting for debugger to connect and then freezes. Also a

第92集《大佛顶首楞严经》

讲义209面   我们在正念真如的过程当中,主要有二种的方法:第一个就是依教起观。就是我们根据本经的语言文字的教法,来生起观照。比方说佛陀告诉我们经常能够回光返照:你从什么地方来?从语言文字的引导当中,念念之间能够返妄归真,能够远离五蕴的假相,慢慢慢慢地回归到真如的本性,这个是一种依教起观;第二个就是你能够持秘密神咒。我们至诚恳切、一念不生的去持楞严神咒,它也能够达到这种潜移默化之功——

SVN Cornerstone 报错信息 xcodeproj cannot be opened because the project file cannot be parsed.

svn点击update 之后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened because the project file cannot be parsed. 发现项目中代码全没了。只有一个空的工程名字,因为xcodeproj工程文件冲突了,然后就是svn强制给你更新了,内部的文件冲突了,你们改了同样的地方的一段代码,可能是你们只是多加

Android Studio打开Modem模块出现:The project ‘***‘ is not a Gradle-based project

花了挺长时间处理该问题,特记录如下:1.背景: 在Android studio 下导入一个新增的modem模块,如MPSS.DE.3.1.1\modem_proc\AAA, 目的是看代码方便一些,可以自由搜索各种关键字。但导入该项目时出现了如下错误: The project '***' is not a Gradle-based project.造成的问题: (1) project 下没有代码,而

实习四十:部署project_exam_system项目——及容器的编排

(一)安装docker、编辑daemon.json文件、安装docker-compose编排容器、启动docker 1.环境准备 [root@docker--1 ~]# rz -E   rz waiting to receive.   [root@docker--1 ~]# ls   anaconda-ks.cfg  docker.sh   [root@docker--1 ~]# source

【UVa】 10735 Euler Circuit 混合图的欧拉回路 最大流

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1676 题目要求:求混合图的欧拉回路+输出路径。 题目分析: 先看一段比较流行的说法吧~: -----------------------------------------

解决Re-download dependencies and sync project

解决Re-download dependencies and sync project 问题描述 新建一个工程,报错 Error:Failed to open zip file.Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)<a hr

myEclipse刚打开启动报Errors running builder 'DeploymentBuilder' on project '工程名' xxxNullpointException 的错误

 早上打开myEclipse就会报 Errors running builder 'DeploymentBuilder' on project '工程名' xxxNullpointException 的错误。找了半天,也没有解决方法。终于找到一个看似靠谱的博客 http://5666522.blog.51cto.com/5656522/1238898    解决了该问题 解决方法如