Sub Main()
Dim x As Integer, y As Integer
x = 2
y = 1000
For i As Integer = x To y
Dim sumOfDivisors As Integer = SumOfDivisors(i)
If SumOfDivisors(sumOfDivisors) = i AndAlso i <> sumOfDivisors Then
Console.WriteLine("{0} и {1} являются дружественными числами.", i, sumOfDivisors)
End If
Next
End Sub
Function SumOfDivisors(n As Integer) As Integer
Dim sum As Integer = 1
For i As Integer = 2 To n \ 2
If n Mod i = 0 Then
sum += i
End If
Next
Return sum
End Function