Divisors Of Really Big Numbers
Description:
Introduction
In the land of Mathtopia, King Euler I embarks on his inaugural crusade to purge the holy soil of NerdLand from the unworthy scholars of humanities, reinstating its former glory in STEM.
Yet, only honorable knights may join this esteemed quest. Thus, he must devise a scheme to discern which loyal subjects shall partake in the honor of battle.
Amidst his restless nights, gazing at the stars, and pondering the likelihood of his plan's fruition, a glint of hope emerges. Beholding the night's embrace through his casement, he encounters divine intervention.
Only those who possess qualities akin to those of your greatest knight shall aid you; the others shall betray you.
Perplexed yet invigorated, the king endeavors to decipher the celestial entity's words.
Arranging his n
men in sequence with his most valiant placed at the end, he assigns a numerical worth to each, spanning from 1
to n
. Thus, he determines that only those whose value divides evenly into that of his foremost man shall partake in this grand endeavor.
Task
Given a positive integer n
, return it's divisors, sorted in ascending order, without repetition (1
and n
also count).
Performance
This kata's focus is to test numbers with many of the same smaller prime factors, such as 2 ^ 12345
or 3 ^ 420 * 7 ^ 69
, rather than numbers with few very big prime factors, such as 1,000,000,007
and 500,000,003
.
Thus, giving a max value for n
would be misleading.
However, I can assure you of a few things.
- The length of the output will always be smaller or equal to
1,000,000
. - The given number will never have a prime factor greater that
1000
. - In addition to the fixed tests, there will be
100
random tests, following the aforementioned restrictions.
Also, the answer won't be shown in the full tests; this isn't to avoid cheating but rather to allow big inputs; otherwise, the string conversion for the message would take too long, limiting the possible inputs.
Length Test
Your code shouldn't be longer than 10,000
characters.
Unless you're trying to hardcode some of the answers, this really shouldn't be a problem (reference solution is 476
characters long).
This is just to stop anyone from hardcoding some of the slower inputs.
Examples
divisors(6) -> [1, 2, 3, 6]
divisors(25) -> [1, 5, 25]
divisors(101) -> [1, 101]
divisors(250) -> [1, 2, 5, 10, 25, 50, 125, 250]
# It's just the powers of 3 to 100; I ain't putting them all here, but you have to return them all.
divisors(3 ** 100) -> [1, 3, 9, 27, 81, 243, ..., 515377520732011331036461129765621272702107522001]
Other Katas
Check out https://www.codewars.com/kata/544aed4c4a30184e960010f4, for a less performant version of the same problem (O(n)
works there).
Check out https://www.codewars.com/kata/5bd5607c1c730fe99400000f, for a more big-primes-focused version. It has a lower upper bound, but greater individual factors (the description is also 10%
of this one, lol).
If you're looking for some other dumb math stories, take a look at my other katas, though regarding quality, the introduction is the only certainty at best.
Similar Kata:
Stats:
Created | Dec 5, 2023 |
Published | Dec 6, 2023 |
Warriors Trained | 241 |
Total Skips | 4 |
Total Code Submissions | 514 |
Total Times Completed | 40 |
Python Completions | 40 |
Total Stars | 15 |
% of votes with a positive feedback rating | 83% of 20 |
Total "Very Satisfied" Votes | 15 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 5 kyu |