Q
Q
quarttt2020-11-30 00:38:01
C++ / C#
quarttt, 2020-11-30 00:38:01

How to decompose a number into factors (si)?

Fill in the body of a function that takes a number n and uses pointers to fill two numbers with factors a and b such that:

If n=1 or n is prime, then a = 1, b = n.
If n is composite, then we are looking for ab=n such that 1< a<= b
a is the smallest factor.
It is guaranteed that n>0​​.

void factorize( int n, int* a, int* b )
{
...
}

Can't stop at just two factors. Help, please, to write a function.
I roughly understood how to calculate, but it's a little hard to write a program. Here's what I came up with:
• Half of the numbers are even;
•If the number is odd, then it makes sense to check only odd numbers.
• The divisors of a number do not exceed half of it. In general, even the square root of it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
ZIK1337, 2020-11-30
@ZIK1337

Use Fermat's Algorithm

W
Wataru, 2020-11-30
@wataru

It is impossible to stop at only two multipliers.

Please provide your code that does not stop. In theory, it is enough to insert into it returnafter finding the first pair of factors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question