Largest product in a series

Problem 8

Find the greatest product of five consecutive digits in the 1000-digit number.

73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

 
The code is as follows:
str = "73167176531330624919225119674426574742355349194934\
96983520312774506326239578318016984801869478851843\
85861560789112949495459501737958331952853208805511\
12540698747158523863050715693290963295227443043557\
66896648950445244523161731856403098711121722383113\
62229893423380308135336276614282806444486645238749\
30358907296290491560440772390713810515859307960866\
70172427121883998797908792274921901699720888093776\
65727333001053367881220235421809751254540594752243\
52584907711670556013604839586446706324415722155397\
53697817977846174064955149290862569321978468622482\
83972241375657056057490261407972968652414535100474\
82166370484403199890008895243450658541227588666881\
16427171479924442928230863465674813919123162824586\
17866458359124566529476545682848912883142607690042\
24219022671055626321111109370544217506941658960408\
07198403850962455444362981230987879927244284909188\
84580156166097919133875499200524063689912560717606\
05886116467109405077541002256983155200055935729725\
71636269561882670428252483600823257530420752963450" i = 0
mymax = 0
index = 0
temp = 0
while i <= len(str) - 5:
temp = 1
for j in range(5):
temp *= int(str[i + j])
if temp > mymax:
mymax = temp
index = i
i += 1 print(mymax)
print(index)

  

Project Euler Problem8的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  3. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  6. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

  7. Project Euler 第一题效率分析

    Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

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

    本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...

随机推荐

  1. JavaScript中解决jQuery和Prototype.js同时引入冲突问题

    两个库同时都定义了一个叫$的函数,所以在同时使用的时候会发生冲突.jQuery( http://jquery.com/ https://jquery.org/ )中提供了一种返还$的使用权给其他js库 ...

  2. A1103. Integer Factorization

    The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positi ...

  3. 二分查找、two points、排序

    二分查找 1.查找某元素.循环条件 low <= high,最终结果位mid, 如果查询失败则返回-1. int binSearch(int num[], int low, int high, ...

  4. can't open file 'manage.py': [Errno 2] No such file or directory

    python Django创建数据库时can't open file 'manage.py': [Errno 2] No such file or directory 参考https://blog.c ...

  5. 【Maven】安装配置、目录结构、配置文件、常见命令

    1.下载配置maven步骤 a.windows下配置jdk的系统环境变量:java_home b.windows下配置maven的系统环境变量:maven_home或者m2_home c.window ...

  6. JAVA分布式架构的演进

    系统架构演化历程-初始阶段架构 初始阶段 的小型系统 应用程序.数据库.文件等所有的资源都在一台服务器上通俗称为LAMP 特征:应用程序.数据库.文件等所有的资源都在一台服务器上. 描述:通常服务器操 ...

  7. 对entry-common.S和call.S的部分理解1

    内核版本: linux-2.6.30.4 文件: linux-2.6.30.4/arch/arm/kernel/entry-common.S linux-2.6.30.4/arch/arm/kerne ...

  8. idea常用快捷键及自定义快捷键汇总

    以下都是挨个进行验证过的 生成get和set方法为:alt+insert 自动补全返回值,自动补全变量名称和属性名称:ctrl+alt+v 输入System.out.println()的快捷方法是:输 ...

  9. python 小程序,打印数字

    要求如下: 指定一个数字 x ,然后打印 1到x 的所有数字,并问是否继续打印,否退出程序,是就继续.再指定一个数字 y ,如果 y> x 就显示 x+1 到 y 的所有数字,y <= x ...

  10. round_robin 的几种取值

    ATS-6 的round_robin可以有4种算法可以选择 true Traffic Server goes through the parent cache list in a round robi ...