Little Friday brain test

Soldato
Joined
5 Feb 2006
Posts
3,524
A mate just sent me this. I haven't a clue personally but one of you smart ones might

138 is the smallest three digit number whose digital sum is half digital product. find all three digit numbers with this property, and which are multiples of 5

:)
 
1 x 3 x 8 = 24

1 + 3 + 8 = 12

Find the other three-digit numbers where the second solution is half of the first (and multiples of 5).
 
Hopefully I read this right...for those who don't understand the OP

1+3+8 = 12
1*3*8 = 24

and

24 = 2*12

We need to find all the 3 digit numbers which have this property and are multiples of 5.
 
Last edited:
1 x 3 x 8 = 24

1 + 3 + 8 = 12

Find the other three-digit numbers where the second solution is half of the first (and multiples of 5).

Ahhh right, when he said 'digital sum' I thought he meant that if you were to covert the number 138 into digital (1's and 0's) all the 1's would add up to 69 :p
 

This.

Code:
For num = 100 To 999
	digSum = 0
	digProd = 1
	For i=1 To Len(num)
		dig = Mid(num,i,1)
		digSum = digSum + dig
		digProd = digProd * dig
	Next

	If (digProd = 2 * digSum) = True Then
		If num Mod 5 = 0 Then
			WScript.Echo num
		End If
	End If
Next

WScript.Quit
 
Yay! :D

Here is my code :) Not quite as pretty....and i cheated slightly working out multiples of 5 :p

Code:
List<int> answers = new List<int>();
for (int i = 100; i < 1000; i++)
{

    string first = i.ToString().Substring(0, 1);
    string second = i.ToString().Substring(1, 1);
    string third = i.ToString().Substring(2, 1);

    int firstnum = int.Parse(first);
    int secondnum = int.Parse(second);
    int thirdnum = int.Parse(third);
    if(thirdnum == 5 || thirdnum == 0)
    {
        if (((firstnum * secondnum * thirdnum)/2) == (firstnum + secondnum + thirdnum))
        {
            answers.Add(i);
        }
    }
}
 
Last edited:
Back
Top Bottom