Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2 factors factorization

Given a natural number n write a program or function to get a list of all the possible two factors multiplications that can be used to achieve n. To understand better what is pretended you can go to http://factornumber.com/?page=16777216 to see when n is 16777216 we get the following list:

 2 ×ばつ 8388608 
 4 ×ばつ 4194304 
 8 ×ばつ 2097152 
 16 ×ばつ 1048576 
 32 ×ばつ 524288 
 64 ×ばつ 262144 
 128 ×ばつ 131072 
 256 ×ばつ 65536 
 512 ×ばつ 32768 
1024 ×ばつ 16384
2048 ×ばつ 8192
4096 ×ばつ 4096

No need to pretty print things like here. The requirement is that each entry (pair of factors) is well distinguished from each other and inside each pair, the first factor is also well distinguished from the other. If you choose to return a list/array, the inside element can be a list/array with two elements, or some structure of your language that supports a pair of things like C++ std::pair.

Do not print the multiplication by 1 entry, nor repeat entries with the first factor commuted by the second, as they are pretty useless.

No winner; it will be a per language basis code golf.

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ tio.run/##FcnRCoMgFAbgVzk3AwVh84AQsu0RfIHqwig3YfsNk2BEz27r7oNv/… — Memory error? \$\endgroup\$ Commented Dec 5, 2017 at 0:30
  • \$\begingroup\$ @sergiol Yes, a MemoryError, since Python tries to evaluate range(2,N) and store it as a list, yet the allocated memory does not suffice. One could try replace range with xrange (Python 2's range generator), though this exceeds TIO's one minute of maximum runtime. On a machine with enough memory and time, this program should terminate and return the correct answer. \$\endgroup\$ Commented Dec 5, 2017 at 16:01

AltStyle によって変換されたページ (->オリジナル) /