factorpairs

版本 1.0.0.0 (2.1 KB) 作者: John D'Errico
Generate all pairs of factors N = p*q, p <= q, for positive integer N
772.0 次下载
更新时间 2010/3/29

查看许可证

I needed a tool that would generate all simple pairs of factors of a positive integer N, where N could be rather large. I also needed this task to be accomplished efficiently. So while I liked the nfactork submission that Matt Fig has posted, I found it to have severe problems with memory for some numbers. Therefore I had to write my own tool for the task that handles the case where exactly two factors are generated.

factorpairs(72)
ans =
1 72
2 36
3 24
4 18
6 12
8 9

The factorpairs function is quite efficient for large N with many factors. It works for any value of N that does not exceed 2^32.

tic
F = factorpairs(factorial(12));
toc

Elapsed time is 0.003767 seconds.

There are 396 distinct pairs of factors generated here.

size(F)
ans =
396 2

引用格式

John D'Errico (2024). factorpairs (https://www.mathworks.com/matlabcentral/fileexchange/27113-factorpairs), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2010a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0