use a sage function for polygonal numbers

This commit is contained in:
filifa 2025-04-19 20:42:09 -04:00
parent 4f40147212
commit a881f7518d
1 changed files with 2 additions and 2 deletions

View File

@ -7,7 +7,7 @@
"source": [ "source": [
"# [Highly Divisible Triangular Number](https://projecteuler.net/problem=12)\n", "# [Highly Divisible Triangular Number](https://projecteuler.net/problem=12)\n",
"\n", "\n",
"Yet another problem with a straightforward solution thanks to SageMath's preinstalled functions. We'll also once again apply the closed formula for triangle numbers (see [problem 1](https://projecteuler.net/problem=1))." "Yet another problem with a straightforward solution thanks to SageMath's preinstalled functions. Triangular numbers fall into the broader category of [polygonal numbers](https://en.wikipedia.org/wiki/Polygonal_number)."
] ]
}, },
{ {
@ -26,7 +26,7 @@
], ],
"source": [ "source": [
"for n in PositiveIntegers():\n", "for n in PositiveIntegers():\n",
" t = n * (n+1) / 2\n", " t = polygonal_number(3, n)\n",
" if number_of_divisors(t) > 500:\n", " if number_of_divisors(t) > 500:\n",
" print(t)\n", " print(t)\n",
" break" " break"