Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question