Euler习题
采用MATLAB和C#或者Python实现Euler习题
qshbbh
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
欧拉习题12
题目见:https://projecteuler.net/problem=12这个题目涉及到两个知识点:一个是等差数列的求和公式,另外一个是一个数的约数个数公式,MATLAB和Python的实现分别用了两种不同的思路MATLAB代码clear;clc;close allsum(1:find(arrayfun(@(i)prod(accumarray(factor(sum(1:i))',1)+1),... 1:1.5e4)>500,1))Python代码import sy原创 2021-01-08 00:33:02 · 459 阅读 · 0 评论
-
欧拉习题40
题目如下:An irrational decimal fraction is created by concatenating the positive integers:0.123456789101112131415161718192021...It can be seen that the 12thdigit of the fractional part is 1.Ifdnrepresents thenthdigit of the fractional part, find ...原创 2021-11-13 16:55:14 · 677 阅读 · 0 评论 -
欧拉习题39
题目如下Ifpis the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions forp= 120.{20,48,52}, {24,45,51}, {30,40,50}For which value ofp≤ 1000, is the number of solutions maximised?代码clear;...原创 2021-11-13 16:53:21 · 737 阅读 · 0 评论 -
欧拉习题38
题目如下: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 s原创 2021-11-13 16:51:27 · 908 阅读 · 0 评论 -
欧拉习题37
题目如下:The number 3797 has an interesting property. Being prime itself, it is possible to 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.原创 2021-11-13 16:48:30 · 842 阅读 · 0 评论 -
欧拉习题36
题目如下: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 inclu.原创 2021-11-13 08:45:57 · 839 阅读 · 0 评论 -
欧拉习题35
题目如下: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 t原创 2021-11-13 00:46:06 · 756 阅读 · 0 评论 -
欧拉习题34
题目如下: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 their digits.Note: As 1! = 1 and 2! = 2 are not sums they are not included.采用暴力方法clear;clc;close all原创 2021-11-13 00:17:10 · 693 阅读 · 0 评论 -
欧拉习题33
题目如下The fraction49/98is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that49/98=4/8, which is correct, is obtained by cancelling the 9s.We shall consider fractions like,30/50=3/5, to...原创 2021-11-12 23:11:01 · 1087 阅读 · 0 评论 -
欧拉习题32
题目如下:We shall say that ann-digit number is pandigital if it makes use of all the digits 1 tonexactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing m...原创 2021-11-12 22:38:23 · 688 阅读 · 0 评论 -
欧拉习题31
题目如下:In the United Kingdom the currency is made up of pound (£) and pence (p). There are eight coins in general circulation:1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), and £2 (200p).It is possible to make £2 in the following way:1×£1 + 1×50p + 2×20p + 1原创 2021-11-12 12:07:05 · 1643 阅读 · 0 评论 -
欧拉习题30
题目如下:Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:As 1 = is not a sum it is not included.The sum of these numbers is 1634 + 8208 + 9474 = 19316.Find the sum of all the numbers that ..原创 2021-11-02 11:10:20 · 753 阅读 · 0 评论 -
欧拉习题29
题目如下:Consider all integer combinations ofabfor 2 ≤a≤ 5 and 2 ≤b≤ 5:=4, =8, =16, =32=9, =27, =81, =243=16, =64, =256, =1024=25, =125, =625, =3125If they are then placed in numerical order, with any repeats removed, we get the following sequence...原创 2021-11-02 11:05:32 · 669 阅读 · 0 评论 -
欧拉习题28
题目如下:Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:2122 23 242520 78 91019 6 12 1118 54 3121716 15 1413It can be verified that the sum of the numbers on the diag...原创 2021-11-02 10:50:30 · 647 阅读 · 0 评论 -
欧拉习题27
题目如下:Euler discovered the remarkable quadratic formula:It turns out that the formula will produce 40 primes for the consecutive integer values0≤n≤39. However, whenn=40,+40+41=40(40+1)+41is divisible by 41, and certainly whenn=41,+41+41is clearl...原创 2021-11-02 10:39:34 · 857 阅读 · 0 评论 -
欧拉习题26
题目如下: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.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6) 1/7 = 0...原创 2021-11-01 15:38:20 · 764 阅读 · 0 评论 -
欧拉习题25
题目如下:The Fibonacci sequence is defined by the recurrence relation:Hence the first 12 terms will be:The 12th term, F12, is the first term to contain three digits.What is the index of the first term in the Fibonacci sequence to contain 1000 digi原创 2021-11-01 15:16:47 · 605 阅读 · 0 评论 -
欧拉习题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 order. The lexicographic pe原创 2021-11-01 15:02:07 · 788 阅读 · 0 评论 -
欧拉习题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 numbernis called..原创 2021-11-01 14:52:49 · 1281 阅读 · 0 评论 -
欧拉习题22
题目如下:Usingnames.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 al..原创 2021-11-01 14:06:28 · 687 阅读 · 0 评论 -
欧拉习题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 many letters would原创 2021-11-01 12:29:45 · 827 阅读 · 0 评论 -
欧拉习题16
题目如下:and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is the sum of the digits of the number ?数值计算不行,采用符号计算sum(char(sym(2)^1000)-'0')原创 2021-11-01 01:15:39 · 204 阅读 · 0 评论 -
欧拉习题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?这属于经典的排列组合题目,常在小学奥数上出现,一般有两种做法,动态规划和组原创 2021-11-01 01:08:49 · 319 阅读 · 0 评论 -
欧拉习题14
题目如下:The following iterative sequence is defined for the set of positive integers:n→n/2 (nis even)n→ 3n+ 1 (nis odd)Using the rule above and starting with 13, we generate the following sequence:13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1It...原创 2021-11-01 00:55:02 · 376 阅读 · 0 评论 -
欧拉习题13
题目如下:Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.371072875339021027987979982208375902465101357402504637693767749000971264812489697007805041701826053874324986199524741059474233309513058123726617309629919422原创 2021-11-01 00:24:39 · 292 阅读 · 0 评论 -
欧拉习题21
题目如下:Let d(n) be defined as the sum of proper divisors ofn(numbers less thannwhich divide evenly inton).If d(a) =band d(b) =a, wherea≠b, thenaandbare an amicable pair and each ofaandbare called amicable numbers.For example, the pro...原创 2021-10-31 00:54:53 · 334 阅读 · 0 评论 -
欧拉习题20
题目如下:n! meansn× (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!MATLAB需要采用符号计算sum(char...原创 2021-10-31 00:41:47 · 240 阅读 · 0 评论 -
欧拉习题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 has twenty-e原创 2021-10-31 00:22:55 · 264 阅读 · 0 评论 -
欧拉习题67
该题目和第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.3742468 593That is, 3 + 7 + 4 + 9 = 23.Find the maximum total from top to bottom int...原创 2021-10-28 23:34:22 · 296 阅读 · 0 评论 -
欧拉习题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.3742468 593That is, 3 + 7 + 4 +...原创 2021-10-28 15:13:14 · 291 阅读 · 0 评论 -
欧拉习题11
题目:https://projecteuler.net/problem=11将文本复制到data.txtMATLAB代码clear;clc;close allfun = @(x)max([prod(diag(x)),... prod(diag(flip(x))),... prod(x),prod(x')]);s3 = max(nlfilter(readmatrix("data.txt"),[4 4],fun),[],'all')python代码import sys原创 2020-12-23 12:36:57 · 593 阅读 · 0 评论 -
欧拉习题10
题目:https://projecteuler.net/problem=10MATLAB代码>> sum(primes(2e6))ans = 142913828922Python代码import mathprimes = [2]t = 1while t <= 2e6: t += 2 isprime = True for i in primes: if t%i == 0:原创 2020-12-21 20:51:04 · 262 阅读 · 0 评论 -
欧拉习题9
题目:https://projecteuler.net/problem=9找个题目就是考察基本的循环和判断MATLAB代码[a, b] = meshgrid(1:500);c = 1000 - a - b;idx = hypot(a,b) == c;max(a(idx).*b(idx).*c(idx))Python代码s = [a*b*(1000-a-b) for a in range(1,500) for b in range(a+1,500) if a*a + b*b =原创 2020-12-20 21:52:01 · 200 阅读 · 0 评论 -
欧拉习题8
题目:https://projecteuler.net/problem=8这个题目要求找出连续13个数字相乘的最大值,因为文本关系,需要去掉换行符将数字复制下来保存到文本中,命名为data.txtMATLAB代码>> max(movprod(str2double(regexp(fileread('data.txt'),'\d','match')),13))ans = 23514624000Python代码import sysf =原创 2020-12-19 00:16:01 · 409 阅读 · 2 评论 -
欧拉习题7
题目:https://projecteuler.net/problem=7此题目还是考察质数的判断方法,用MATLAB比较简单>> feval(@(x)x(10001),primes(2e5))ans = 104743下面是Python实现primes = [2]t = 2while len(primes) <= 10000: t += 1 isprime = True for i in primes: if原创 2020-12-17 20:11:22 · 440 阅读 · 0 评论 -
欧拉习题6
题目:https://projecteuler.net/problem=6这个题目比较简单,用数列的求和公式或者程序遍历都可以求解MATLAB代码>> sum(1:100)^2-sumsqr(1:100)ans = 25164150Python代码t1 = sum([i for i in range(1,101)])t2 = sum([i*i for i in range(1,101)]);print(t1*t1-t2)...原创 2020-12-17 17:33:57 · 292 阅读 · 0 评论 -
欧拉习题5
题目:https://projecteuler.net/problem=5题目是找1~20的所有数字的最小公倍数,MATLAB有函数,lcm,当然也可以找出每个质因数的个数,比如20之内2的个数不超过4个,因为2^5>20了,而3的个数不超过2和,因为3^3>20MATLAB代码>> prod(repelem(primes(20),floor(log(20)./log(primes(20)))))ans = 232792560Python代码用辗转相原创 2020-12-16 00:01:44 · 392 阅读 · 1 评论 -
欧拉习题4
题目:https://projecteuler.net/problem=4题目的意思是找到两个三位数相乘的最大的回文数MATLAB代码>> max(feval(@(a)a(reverse(string(a))==string(a)), (100:999).*(100:999)'))ans = 906609Python代码import mathimport operators = 0for k in [i*j for i in range(100,9原创 2020-12-15 10:35:00 · 284 阅读 · 0 评论 -
欧拉习题3
题目:https://projecteuler.net/problem=3该题目是寻找给定数字的最大的质因数MATLAB代码>> max(factor(600851475143))ans = 6857Python代码import matha = 600851475143 def isprime(x): for i in range(2,math.floor(math.sqrt(x))): if x%i == 0:原创 2020-12-14 23:08:36 · 260 阅读 · 0 评论 -
欧拉习题2
题目见:https://projecteuler.net/problem=2本题目的解法很多,我只是用自己习惯的方式来求解>> sum(fibonacci(3:3:log(4e6*sqrt(5))/log(sqrt(5)/2+0.5)))ans = 4613732注意: fibpnacci是MATLAB自带的函数>> which fibonacci -allC:\Program Files\Polyspace\R2020b\toolbox\.原创 2020-12-14 18:00:43 · 247 阅读 · 0 评论
分享