Project Euler问题程序解
文章平均质量分 84
Project Euler的每一个问题都十分经典,有些像是数学问题,又需要计算来解决,看似简单,都需要费一番功夫。本题解使用了许多高度的程序设计技巧,可以作为程序员的基础练习。
海岛Blog
专注于程序设计及其竞赛,专注于集成电路EDA设计
展开
-
Project Euler Problem 26 Reciprocal cycles
Reciprocal cyclesProblem 26A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:1/2= 0.51/3原创 2017-04-01 10:31:42 · 969 阅读 · 0 评论 -
Project Euler Problem 27 Quadratic primes
Quadratic primesProblem 27Euler discovered the remarkable quadratic formula:n2+n+41It turns out that the formula will produce 40 primes for the consecutive integer values0≤n≤39.原创 2017-03-30 19:46:48 · 968 阅读 · 0 评论 -
Project Euler Problem 118 Pandigital prime sets
Pandigital prime setsProblem 118Using all of the digits 1 through 9 and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set {2,5,47,8原创 2017-03-30 18:52:29 · 1192 阅读 · 0 评论 -
Project Euler Problem 36 Double-base palindromes
Double-base palindromesProblem 36The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.Find the sum of all numbers, less than one million, which are palindromic in b原创 2017-03-30 01:00:00 · 1148 阅读 · 0 评论 -
Project Euler Problem 38 Pandigital multiples
Pandigital multiplesProblem 38Take the number 192 and multiply it by each of 1, 2, and 3:192 × 1 = 192192 × 2 = 384192 × 3 = 576By concatenating each product we get the 1 to 9 pa原创 2017-03-29 22:00:47 · 878 阅读 · 0 评论 -
Project Euler Problem 104 Pandigital Fibonacci ends
Pandigital Fibonacci endsProblem 104The Fibonacci sequence is defined by the recurrence relation:Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.It turns out that F541, which contains 113原创 2017-03-29 11:38:13 · 905 阅读 · 2 评论 -
Project Euler Problem 32 Pandigital products
Pandigital productsProblem 32We shall say that an n-digit number is pandigital if it makes use of all the digits 1 ton exactly once; for example, the 5-digit number, 15234, is 1 through 5原创 2017-03-29 06:38:22 · 1076 阅读 · 0 评论 -
Project Euler Problem 41 Pandigital prime
Pandigital primeProblem 41We shall say that an n-digit number is pandigital if it makes use of all the digits 1 ton exactly once. For example, 2143 is a 4-digit pandigital and is also prim原创 2017-03-28 18:32:56 · 714 阅读 · 1 评论 -
Project Euler Problem 34 Digit factorials
Digit factorialsProblem 34145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.Find the sum of all numbers which are equal to the sum of the factorial of their digits.Note: as 1原创 2017-03-28 17:48:12 · 718 阅读 · 0 评论 -
Project Euler Problem 23 Non-abundant sums
Non-abundant sumsProblem 23A 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原创 2017-03-28 09:58:12 · 839 阅读 · 0 评论 -
Project Euler Problem 24 Lexicographic permutations
Lexicographic permutationsProblem 24A 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原创 2017-03-28 08:21:42 · 862 阅读 · 0 评论 -
Project Euler Problem 19 Counting Sundays
Counting SundaysProblem 19You 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, Ju原创 2017-03-27 04:01:18 · 958 阅读 · 0 评论 -
Project Euler Problem 17 Number letter counts
Number letter countsProblem 17If 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 fr原创 2017-03-26 15:56:58 · 909 阅读 · 0 评论 -
Project Euler Problem 92 Square digit chains
Square digit chainsProblem 92A 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原创 2017-03-25 08:37:03 · 1018 阅读 · 4 评论 -
Project Euler Problem 543 Prime-Sum Numbers
Prime-Sum NumbersProblem 543Define function P(n,k) = 1 ifn can be written as the sum of k prime numbers (with repetitions allowed), and P(n,k) = 0 otherwise.For example, P(10,2) = 1 beca原创 2017-03-24 08:03:34 · 1207 阅读 · 2 评论 -
Project Euler Problem 99 Largest exponential
Largest exponentialProblem 99Comparing two numbers written in index form like 211 and 37 is not difficult, as any calculator would confirm that 211 = 2048 7 = 2187.However, confirming that原创 2017-03-23 21:11:36 · 755 阅读 · 0 评论 -
Project Euler Problem 21 Amicable numbers
Amicable numbersProblem 21Let d(n) be defined as the sum of proper divisors ofn (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原创 2017-03-23 09:11:11 · 780 阅读 · 0 评论 -
Project Euler Problem 25 1000-digit Fibonacci number
1000-digit Fibonacci numberProblem 25The Fibonacci sequence is defined by the recurrence relation:Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.Hence the first 12 terms will be:F1 =原创 2017-03-23 06:35:05 · 600 阅读 · 0 评论 -
Project Euler Problem 20 Factorial digit sum
Factorial digit sumProblem 20n! means n × (n − 1) × ... × 3 × 2 × 1For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8原创 2017-03-23 00:10:55 · 770 阅读 · 0 评论 -
Project Euler Problem 67 Maximum path sum II
Maximum path sum IIProblem 67By 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.37 42 4 68 5 9 3原创 2017-03-22 23:06:04 · 620 阅读 · 0 评论 -
Project Euler Problem 18 Maximum path sum I
Maximum path sum IProblem 18By 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.37 42 4 68 5 9 3原创 2017-03-22 22:54:39 · 766 阅读 · 0 评论 -
Project Euler Problem 16 Power digit sum
Power digit sumProblem 16215 = 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?C++:#include #include using namespace原创 2017-03-22 19:27:54 · 524 阅读 · 0 评论 -
Project Euler Problem 47 Distinct primes factors
Distinct primes factorsProblem 47The first two consecutive numbers to have two distinct prime factors are:14 = 2 × 715 = 3 × 5The first three consecutive numbers to have three distinct原创 2017-03-22 18:19:33 · 696 阅读 · 0 评论 -
Project Euler Problem 15 Lattice paths
Lattice pathsProblem 15Starting 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 man原创 2017-03-22 05:54:11 · 672 阅读 · 2 评论 -
Project Euler Problem 14 Longest Collatz sequence
Longest Collatz sequenceProblem 14The 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原创 2017-03-21 10:06:01 · 525 阅读 · 0 评论 -
Project Euler Problem 13 Large sum
Large sumProblem 13Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.3710728753390210279879799822083759024651013574025046376937677490009712648124896970原创 2017-03-20 23:50:09 · 569 阅读 · 0 评论 -
Project Euler Problem 12: Highly divisible triangular number
Highly divisible triangular numberProblem 12The 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. T原创 2017-03-20 22:16:44 · 700 阅读 · 0 评论 -
Project Euler Problem 11: Largest product in a grid
Largest product in a gridProblem 11In 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 0849 49 99原创 2017-03-20 20:39:44 · 565 阅读 · 0 评论 -
Project Euler Problem 10: Summation of primes
Summation of primesProblem 10The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million.C++:#include #include #include using namespac原创 2017-03-20 01:16:20 · 511 阅读 · 0 评论 -
Project Euler Problem 9: Special Pythagorean triplet
Special Pythagorean tripletProblem 9A Pythagorean triplet is a set of three natural numbers,a b c, for which,a2 + b2 =c2For example, 32 + 42 = 9 + 16 = 25 = 52.There exists exa原创 2017-03-20 00:09:06 · 427 阅读 · 0 评论 -
Project Euler Problem 8: Largest product in a series
Largest product in a seriesProblem 8The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.7316717653133062491922511967442657474235534919原创 2017-03-19 16:53:35 · 486 阅读 · 0 评论 -
Project Euler Problem 7: 10001st prime
10001st primeProblem 7By 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?C++:#include #include原创 2017-03-19 15:02:36 · 564 阅读 · 0 评论 -
Project Euler Problem 48: Self powers
Self powersProblem 48The series, 11 + 22 + 33 + ... + 1010 = 10405071317.Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.C++:#include using namespace std;原创 2017-03-19 08:59:32 · 1014 阅读 · 3 评论 -
Project Euler Problem 6: Sum square difference
Sum square differenceProblem 6The sum of the squares of the first ten natural numbers is,12 + 22 + ... + 102 = 385The square of the sum of the first ten natural numbers is,(1 + 2原创 2017-03-19 08:03:28 · 435 阅读 · 0 评论 -
Project Euler Problem 5: Smallest multiple
Smallest multipleProblem 52520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive number that is evenly di原创 2017-03-19 07:34:21 · 458 阅读 · 0 评论 -
Project Euler Problem 4: Largest palindrome product
Largest palindrome productProblem 4A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.Find the largest pal原创 2017-03-19 06:39:02 · 584 阅读 · 0 评论 -
Project Euler Problem 3: Largest prime factor
Largest prime factorProblem 3The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?C++:#include using namespace std;long m原创 2017-03-18 07:45:22 · 540 阅读 · 0 评论 -
Project Euler Problem 2: Even Fibonacci numbers
Even Fibonacci numbersProblem 2Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:1, 2, 3, 5, 8, 13原创 2017-03-17 23:34:00 · 380 阅读 · 0 评论 -
Project Euler Problem 1: Multiples of 3 and 5
Multiples of 3 and 5Problem 1If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multip原创 2017-03-17 22:20:52 · 503 阅读 · 0 评论