project euler之系列中最大的产品

num=str(7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450)
max = 0
for start in range(0,988):
    if num[start] == 0:#当有数字为0时 直接跳过
        start += 1 #索引值加一
    sum = int(num[start]) * int(num[start+1]) * int(num[start+2]) * int(num[start+3]) * int(num[start+4]) * int(num[start+5]) * int(num[start+6]) * int(num[start+7]) * int(num[start+8]) * int(num[start+9]) * int(num[start+10]) * int(num[start+11]) * int(num[start+12])
    if sum > max:#如果得数大于最大值寄存器 则替代之
        max = sum
        start += 1
        continue
print(max)

原文地址:https://www.cnblogs.com/chif/p/9277647.html

时间: 2024-11-13 15:26:43

project euler之系列中最大的产品的相关文章

Project Euler不断更新中,目前进度(1-1)

慢慢的开始使用Mathematica软件,不过一开始总会带一些C语言的影子 No.1 Mathematica In[21]:= Sum[x, {x, Table[If[Mod[x, 3] == 0, x, If[Mod[x, 5] == 0, x, 0]], {x, 1, 1000}]}] Out[21]= 234168 improve In[24]:= Sum[x, {x, #1}] &@ Table[If[Mod[x, 3] == 0, x, If[Mod[x, 5] == 0, x, 0]

project euler之最大的回文产品

for i in range(998001,888888,-1): num = str(i) start = 0 end = -1 if num[start] == num[end]: start += 1 end -= 1 if num[start] == num[end]: start += 1 end -= 1 if num[start] == num[end]: start += 1 end -= 1 for i in range(999,900,-1): for j in range(

Python练习题 043:Project Euler 015:方格路径

本题来自 Project Euler 第15题:https://projecteuler.net/problem=15 ''' Project Euler: Problem 15: Lattice paths Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right

Android系统中添加一个产品----图文详解

本文本着开源的精神介绍如何向一个Android系统中添加一个产品的整个过程,按照以下过程笔者有理由相信每个将要从事本行业的人都可以完成,其实添加一个产品并不难,难的是对其相关硬件的修改,好了废话不多说. 首先我们要创建一个属于自己产品的目录,这里以WY_device为例,以WY作为产品的名字. 首先从已经存在的产品中拷贝一个以产品的名字为名的.mk文件,修改为自己的.mk文件,在这里为WY.mk 对其进行如下的修改: 然后添加AndroidProducts.mk  这是添加产品的配置文件名路径,

Python练习题 048:Project Euler 021:10000以内所有亲和数之和

本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable numbers Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b

Python练习题 047:Project Euler 020:阶乘结果各数字之和

本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial digit sum n! means n × (n ? 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! i

Python练习题 046:Project Euler 019:每月1日是星期天

本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? Answer: 171 ''' from datetime import * firstDay = date(1901,1,1) lastDay = date(

Python练习题 035:Project Euler 007:第10001个素数

本题来自 Project Euler 第7题:https://projecteuler.net/problem=7 # Project Euler: Problem 7: 10001st prime # By listing the first six prime numbers: # 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. # What is the 10 001st prime number? # Answer

Python练习题 034:Project Euler 006:和平方与平方和之差

本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square difference # The sum of the squares of the first ten natural numbers is, # 1**2 + 2**2 + ... + 10**2 = 385 # The square of the sum of the first ten natur