Numbers which are the cube roots of the product of their proper divisors: Difference between revisions
Content added Content deleted
(→{{header|PL/M}}: Alternative sample based on modular arithmetic and prime factors) |
(→{{header|PL/M}}: typo) |
||
Line 500: | Line 500: | ||
</pre> |
</pre> |
||
Alternative version, calculating the proper divisor products and cubes modulo 65536 (as PL/M uses unsigned |
Alternative version, calculating the proper divisor products and cubes modulo 65536 (as PL/M uses unsigned 16 bit arithmetic and doesn't check for overflow, all calculations are modulo 65536). This is sufficient to detect the numbers apart from those where the product/cube is 0 mod 65536. To handle the zero cases, it uses Rdm's hints (see J sample and Discussion page) that if x = n^3 then the prime factors of x must be the same as the prime factors of n and the prime factors of x must have powers three times those of n - additionally, we don't have to calclate the product of the proper divisors, we only need to factorise them and aggregate their powers.<br> |
||
Using this technique, the first 50 numbers can be found in a few seconds but to find the 5000th takes several minutes. As the candidates increase, the proportion that have cubes that are 0 mod 65536 increases and the factorisation and aggregation is quite expensive (the code could doubtless be improved). |
Using this technique, the first 50 numbers can be found in a few seconds but to find the 5000th takes several minutes. As the candidates increase, the proportion that have cubes that are 0 mod 65536 increases and the factorisation and aggregation is quite expensive (the code could doubtless be improved). |
||
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator) |
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator) |