Enunturi probleme proiectul euler

download Enunturi probleme proiectul euler

If you can't read please download the document

description

Primele 40 de probleme

Transcript of Enunturi probleme proiectul euler

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million.In the 2020 grid below, four numbers along a diagonal line have been marked in red.08 02 22 9749 49 99 4081 49 31 7352 70 95 2322 31 16 7124 47 32 6032 98 81 2867 26 20 6824 55 58 0521 36 23 0978 17 53 2816 39 05 4286 56 00 4819 80 81 6804 52 08 8388 36 68 8704 42 16 7320 69 36 4120 73 35 2901 70 54 71The product3817550451996402667522963505975738727883of15 0081 1879 1460 1167 6303 4523 6762 1273 9900 7675 3135 3171 8994 4735 9962 2025 3930 2331 9051 54these40 00 75 04 05 07 7857 60 87 17 40 98 4329 93 71 40 67 53 8842 69 24 68 56 01 3289 41 92 36 54 22 4002 44 75 33 53 78 3610 26 38 40 67 59 5420 95 63 94 39 63 0826 97 17 78 78 96 8344 20 45 35 14 00 6167 15 94 03 80 04 6247 55 58 88 24 00 1707 05 44 44 37 44 6069 28 73 92 13 86 5216 07 97 57 32 16 2672 03 46 33 67 46 5511 24 94 72 18 08 4688 34 62 99 69 82 6701 74 31 49 71 48 8669 16 92 33 48 61 43numbers is 26 63 52693056408470401433165421172612295981527812 50 77 91 0848 04 56 62 0003 49 13 36 6571 37 02 36 9128 66 33 13 8020 35 17 12 5066 18 38 64 7091 66 49 94 2188 34 89 63 7297 34 31 33 9514 09 53 56 9224 36 29 85 5758 51 54 17 5877 04 89 55 4079 33 27 98 6632 63 93 53 6932 40 62 76 3685 74 04 36 1616 23 57 05 5401 89 19 67 48 14 = 1788696.What is the greatest product of four adjacent numbers in the same direction (up,down, left, right, or diagonally) in the 2020 grid?The sequence of triangle numbers is generated by adding the natural numbers. Sothe 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, ...Let us list the factors of the first seven triangle numbers:1: 13: 1,36: 1,2,3,610: 1,2,5,1015: 1,3,5,1521: 1,3,7,2128: 1,2,4,7,14,28We can see that 28 is the first triangle number to have over five divisors.What is the value of the first triangle number to have over five hundred divisors?Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.37107287533902102798797998220837590246510135740250463769376774900097126481248969700780504170182605387432498619952474105947423330951305812372661730962991942213363574161572522430563301811072406154908250230675882075393461711719803104210475137780632466768926167069662363382013637841838368417873436172675728112879812849979408065481931592621691275889832738442742289174325203219235894228767964876702721893184745144573600130643909116721685684458871160315327670386486105843025439939619828917593665686757934951621764571418565606295021572231965867550793241933316490635246274190492910143244581382266334794475817892575867718337217661963751590579239728245598838407582035653253593990084026335689488301894586282278288018119938482628201427819413994056758715117009439035398664372827112653829987240784473053190104293586865155060062958648615320752733719591914205172558297169388870771546649911559348760353292171497005693854370070576826684624621495650076471787294438377604532826541087568284431911906346940378552177792951453612327252500029607107508256381565671088525835072145876576172410976447339110607218265236877223636045174237069058518606604482076212098132878607339694128114266041808683061932846081119106155694051268969251934325451728388641918047049293215058642563049483624672216484350762017279180399446930047329563406911573244438690812579451408905770622942919710792820955037687525678773091862540744969844508330393682126183363848253301546861961243487676812975343759465158038628759287849020152168555482871720121925776695478182833757993103614740356856449095527097864797581167263201004368978425535399209318374414978068609844840309812907779179908821879532736447567559084803087086987551392711854517078544161852424320693150332599594068957565367821070749269665376763262354472106979395067965269474259770973916669376304263398708541052684708299085211399427365734116182760315001271653786073615010808570091499395125570281987460043753582903531743471732693212357815498262974255273730794953759765105305946966067683156574377167401875275889028025717332296191766687138199318110487701902712526768027607800301367868099252546340106163286652636270218540497705585629946580636237993140746255962240744869082311749777923654662572469233228109171419143028819710328859780666976089293863828502533340334413065578016127815921815005561868836468420090470230530811728164304876237919698424872550366387845831148769693215490281042402013833512446218144177347063783299490636259666498587618221225225512486764533677201869716985443124195724099139590089523100588229554825530026352078153229679624948164195386821877476085327132285723110424803456124867697064507995236377742425354112916842768655389262050249103265729672370191327572567528565324825826546309220705859652229798860272258331913126375147341994889534765745501184957014548792889848568277260777137214037988797153829820378303147352772158034814451349137322665138134829543829199918180278916522431027392251122869539409579530664052326325380441000596549391598795936352974615218550237130764225512118369380358038858490341698116222072977186158236678424689157993532961922624679571944012690438771072750481023908955235974572318970677254791506150550495392297953090112996751986188088225875314529584099251203829009407770775672113067397083047244838165338735023408456470580773088295917476714036319800818712901187549131054712658197623331044818386269515456334926366572897563400500428462801835170705278318394258821455212272512503275512160354698120058176216521282765275169129689778932238195734329339946437501907836945765883352399886755061649651847751807381688378610915273579297013376217784275219262340194239963916804498399317331273132924185707147349566916674687634660915035914677504995186714302352196288948901024233251169136196266227326746080059154747183079839286853520694694454072476841822524674417161514036427982273348055556214818971426179103425986472045168939894221798260880768528778364618279934631376775430780936333301898264209010848802521674670883215120185883543223812876952786713296124747824645386369930090493103636197638780396218407357239979422340623539380833965132740801111666627891981488087797941876876144230030984490851411606618262936828367647447792391803351109890697907148578694408955299065364044742557608365997664579509666024396409905389607120198219976047599490197230297649139826800329731560371200413779037855660850892521673093931987275027546890690370753941304265231501194809377245048795150954100921645863754710598436791786391670211874924319957006419179697775990283006991536871371193661495281130587638027841075444973307840789923115535562561142322423255033685442488917353448899115014406480203690680639606723221932041495354150312888033953605329934036800697771065056663195481234880673210146739058568557934581403627822703280826165707739483275922328459417065250945123252306082291880205877731971983945018088807242966198081119777158542502016545090413245809786882778948721859617721078384350691861554356628840622574736922845095162084960398013400172393067166682355524525280460972253503534226472524250874054075591789781264330331690The 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 8 4 2 1It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.Which starting number, under one million, produces the longest chain?NOTE: Once the chain starts the terms are allowed to go above one million.Starting in the top left corner of a 22 grid, and only being able to move to theright and down, there are exactly 6 routes to the bottom right corner.(see grid pic)How many such routes are there through a 2020 grid?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?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 many letters would be used?NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and fortytwo) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters.The use of "and" when writing out numbers is in compliance with British usage.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.37 42 4 68 5 9 3That is, 3 + 7 + 4 + 9 = 23.Find the maximum total from top to bottom of the triangle below:75951718201988994141537091630464473504010265414871117166628287822377042672443352049810477573285633652838682765030706834725771789233463164032437314530967708037911791677092701652784330983394973958737329516850169314172769385729 4887 40 3153 60 04 23NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o)You are given the following information, but you may prefer to do some researchfor 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 has twenty-eight, rain or shine.And on leap years, twenty-nine.A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.How many Sundays fell on the first of the month during the twentieth century (1Jan 1901 to 31 Dec 2000)?If we list all the natural numbers below 10 that are multiples of 3 or 5, we get3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000.n! 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 + 0 + 0 = 27.Find the sum of the digits in the number 100!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 eachof a and b are called amicable numbers.For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.Evaluate the sum of all the amicable numbers under 10000.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 value by its alphabetical position in the list to obtain a name score.For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 53 = 49714.What is the total of all the name scores in the file?A perfect number is a number for which the sum of its proper divisors is exactlyequal to the number. For example, the sum of the proper divisors of 28 would be1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.A number n is called deficient if the sum of its proper divisors is less than nand it is called abundant if this sum exceeds n.As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematicalanalysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.Find the sum of all the positive integers which cannot be written as the sum oftwo abundant numbers.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 order. The lexicographic permutations of 0, 1 and 2 are:012021102120201210What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5,6, 7, 8 and 9?The 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 = 1F2 = 1F3 = 2F4 = 3F5 = 5F6 = 8F7 = 13F8 = 21F9 = 34F10 = 55F11 = 89F12 = 144The 12th term, F12, is the first term to contain three digits.What is the first term in the Fibonacci sequence to contain 1000 digits?A 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=0.(3)1/4=0.251/5=0.21/6=0.1(6)1/7=0.(142857)1/8=0.1251/9=0.(1)1/10=0.1Where 0.1(6) means 0.166666..., and has a 1 digit recurring cycle. It can be seen that 1/7 has a 6 digit recurring cycle.Find the value of d < 1000 for which 1/d contains the longest recurring cycle inits decimal fraction part.Euler discovered the remarkable quadratic formula:n^2 + n + 41It turns out that the formula will produce 40 primes for the consecutive valuesn = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisibleby 41, and certainly when n = 41, 41 + 41 + 41 is clearly divisible by 41.The incredible formula n^279n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, 79 and 1601, is 126479.Considering quadratics of the form:n + an + b, where |a| < 1000 and |b| < 1000where |n| is the modulus/absolute value of ne.g. |11| = 11 and | 4| = 4Find the product of the coefficients, a and b, for the quadratic expression thatproduces the maximum number of primes for consecutive values of n, starting with n = 0.Starting with the number 1 and moving to the right in a clockwise direction a 5by 5 spiral is formed as follows:21201918172276516238141524923142510111213It can be verified that the sum of the numbers on the diagonals is 101.What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formedin the same way?Consider all integer combinations of ab for 2 a 5 and 2 b 5:22=4, 23=8, 24=16, 25=3232=9, 33=27, 34=81, 35=24342=16, 43=64, 44=256, 45=102452=25, 53=125, 54=625, 55=3125If they are then placed in numerical order, with any repeats removed, we get thefollowing sequence of 15 distinct terms:4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125How many distinct terms are in the sequence generated by ab for 2 a 100 and 2 b 100?Each new term in the Fibonacci sequence is generated by adding the previous twoterms. By starting with 1 and 2, the first 10 terms will be:1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even valued terms.Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:163482089474As 1====14849414+ 64 ++ 24 ++ 44 +is not34 + 4404 + 8474 + 44a sum it is not included.The sum of these numbers is 1634 + 8208 + 9474 = 19316.Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.In England the currency is made up of pound, , and pence, p, and there are eightcoins in general circulation:1p, 2p, 5p, 10p, 20p, 50p, 1 (100p) and 2 (200p).It is possible to make 2 in the following way:11 + 150p + 220p + 15p + 12p + 31pHow many different ways can 2 be made using any number of coins?We shall say that an n digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5 digit number, 15234, is 1 through 5pandigital.The product 7254 is unusual, as the identity, 39 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.Find the sum of all products whose multiplicand/multiplier/product identity canbe written as a 1 through 9 pandigital.HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.We shall consider fractions like, 30/50 = 3/5, to be trivial examples.There are exactly four non trivial examples of this type of fraction, less thanone in value, and containing two digits in the numerator and denominator.If the product of these four fractions is given in its lowest common terms, findthe value of the denominator.145 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 theirdigits.Note: as 1! = 1 and 2! = 2 are not sums they are not included.The number, 197, is called a circular prime because all rotations of the digits:197, 971, and 719, are themselves prime.There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.How many circular primes are there below one million?The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.(Please note that the palindromic number, in either base, may not include leading zeros.)The number 3797 has an interesting property. Being prime itself, it is possibleto continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37,and 3.Find the sum of the only eleven primes that are both truncatable from left to right and right to left.NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.Take 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 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).What is the largest 1 to 9 pandigital 9 digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.{20,48,52}, {24,45,51}, {30,40,50}For which value of p 1000, is the number of solutions maximised?The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?An irrational decimal fraction is created by concatenating the positive integers:0.123456789101112131415161718192021...It can be seen that the 12th digit of the fractional part is 1.If dn represents the nth digit of the fractional part, find the value of the following expression.d1 d10 d100 d1000 d10000 d100000 d1000000We shall say that an n digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4 digit pandigital and is also prime.What is the largest n digit pandigital prime that exists?The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.A palindromic number reads the same both ways. The largest palindrome made fromthe product of two 2 digit numbers is 9009 = 91 99.Find the largest palindrome made from the product of two 3 digit numbers.2520 is the smallest number that can be divided by each of the numbers from 1 to10 without any remainder.What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?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.37 42 4 68 5 9 3That is, 3 + 7 + 4 + 9 = 23.Find the maximum total from top to bottom in triangle.txt (right click and 'SaveLink/Target As...'), a 15K text file containing a triangle with one hundred rows.NOTE: This is a much more difficult version of Problem 18. It is not possible totry every route to solve this problem, as there are 299 altogether! If you could check one trillion (1012) routes every second it would take over twenty billion years to check them all. There is an efficient algorithm to solve it. ;o)The 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 + ... + 10)2 = 552 = 3025Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see thatthe 6th prime is 13.What is the 10 001st prime number?In the 5 by 5 matrix below, the minimal path sum from the top left to the bottomright, by only moving to the right and down, is indicated in bold red and is equal to 2427.Find the minimal path sum, in matrix.txt (right click and "Save Link/Target As..."), a 31K text file containing a 80 by 80 matrix, from the top left to the bottom right by only moving right and down.The four adjacent digits in the 1000 digit number that have the greatest productare 9 9 8 9 = 5832.7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450Find the thirteen adjacent digits in the 1000 digit number that have the greatest product. What is the value of this product?A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,a^2 + b^2 = c^2For example, 32 + 42 = 9 + 16 = 25 = 52.There exists exactly one Pythagorean triplet for which a + b + c = 1000.Find the product abc.