How to determine the number of common factors?

G

Guest

Does anyone have any suggestions on how to determine the number of common
factors based on given number? For example,
10 is given in cell A1, then the common factors for 10 are 1,2,5,10. There
are 4 numbers for common factors, then I will return 4 in cell B1.
I will try different number in cell A1,
Does anyone have any suggestions on how to determine the number of common
factors in cell B2?
Thanks in advance for any suggestions
Eric
 
G

Guest

Use the function below. Call with

=NumberFactors(10)

Function NumberFactors(target)

'include target
'then you only need to check 1/2 the numbers
NumberFactors = 1
For i = 1 To target / 2
If target Mod i = 0 Then
NumberFactors = NumberFactors + 1
End If
Next i

End Function
 
T

T. Valko

Try this:

=SUMPRODUCT(--(MOD(A1,ROW(INDIRECT("1:"&A1)))=0))

Works only with integers. If the number is 0 you'll get an error. If it's
possible that the number can be 0 then use this version:

=IF(AND(ISNUMBER(A1),A1=0),1,SUMPRODUCT(--(MOD(A1,ROW(INDIRECT("1:"&A1)))=0)))
 
T

T. Valko

Improvement:

This takes care of 0 in a different way and accounts for an empty cell:

=IF(A1="","",SUMPRODUCT(--(MOD(A1,ROW(INDIRECT("1:"&MAX(1,A1))))=0)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top