Problem 24 Lexicographic permutations

Problem 24: Lexicographic permutations

https://projecteuler.net/problem=24

A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic or[……]

>> 阅读全文…

Problem 23 Non-abundant sums

Problem 23: Non-abundant sums

https://projecteuler.net/problem=23

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.

A num[……]

>> 阅读全文…

Problem 22 Names scores

Problem 22: Names scores

https://projecteuler.net/problem=22

Using names.txt (right click and ‘Save Link/Target As…’), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this valu[……]

>> 阅读全文…

Problem 21 Amicable numbers

Problem 21: Amicable numbers

https://projecteuler.net/problem=21

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, then a and b are an amicable pair and each of a and b are called amicable numbers.

For ex[……]

>> 阅读全文…

Problem 20 Factorial digit sum

Problem 20: Factorial digit sum

https://projecteuler.net/problem=20

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! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!

分析

计算100!各位[……]

>> 阅读全文…

Problem 19 Counting Sundays

Problem 19: Counting Sundays

https://projecteuler.net/problem=19

You are given the following information, but you may prefer to do some research for yourself.

  • 1 Jan 1900 was a Monday.
  • Thirty days has September,
    April, June and November.
    All the rest have thirty-one,
    Saving February alone,
    Which h[……]

    >> 阅读全文…

Problem 18 Maximum path sum I

Problem 18: Maximum path sum I

https://projecteuler.net/problem=18

By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.

   3
  7 4
 2 4 6
8 5 9 3

That is, 3 + 7 + 4 + 9 = 23.

Find the maximum total from top to bot[……]

>> 阅读全文…

Problem 17 Number letter counts

Problem 17: Number letter counts

https://projecteuler.net/problem=17

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how m[……]

>> 阅读全文…

Problem 16 Power digit sum

Problem 16: Power digit sum

https://projecteuler.net/problem=16

215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 21000?

分析

2的1000次方的各位数字和

2的1000次方很大,C\C++中long long都已经不够了,所以比较难解。如果用Python,一行代码就可以解决。

方法1 使用字符串实现乘法

与 Problem 20 基本相同。将21000转[……]

>> 阅读全文…

Problem 15 Lattice paths

Problem 15: Lattice paths

https://projecteuler.net/problem=15

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 corner.

How many such routes are there through a 20×20 grid?

分析

20×20的方格,从左上角到右下角的路径条数。由题可[……]

>> 阅读全文…

Problem 14 Longest Collatz sequence

Problem 14: Longest Collatz sequence

https://projecteuler.net/problem=14

The following iterative sequence is defined for the set of positive integers:

n → n/2 (n is even)
n → 3n + 1 (n is odd)

Using the rule above and starting with 13, we generate the following sequence:

13 → 40 → 20 → 10 → 5 → 16[……]

>> 阅读全文…

Problem 13 Large sum

Problem 13: Large sum

https://projecteuler.net/problem=13

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.

37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629[……]

>> 阅读全文…

Problem 12 Highly divisible triangular number

Problem 12: Highly divisible triangular number

https://projecteuler.net/problem=12

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …[……]

>> 阅读全文…

Problem 11 Largest product in a grid

Problem 11: Largest product in a grid

https://projecteuler.net/problem=11

In the 20×20 grid below, four numbers along a diagonal line have been marked in red.

08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 1[……]

>> 阅读全文…

Problem 10 Summation of primes

Problem 10: Summation of primes

https://projecteuler.net/problem=10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

分析

2百万以内的所有质数的和。

这题考察的重点应该是大数的存储,因为2百万以内所有质数的和是个非常大的数,超过了int型能表示的范围。如果是C\C++就需要使用更大的数据类型,当然Python就不用考虑这些了。至于判断质数的方法,和 Problem[……]

>> 阅读全文…