Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
42
Task/Count-in-factors/Visual-Basic-.NET/count-in-factors.vb
Normal file
42
Task/Count-in-factors/Visual-Basic-.NET/count-in-factors.vb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
Module CountingInFactors
|
||||
|
||||
Sub Main()
|
||||
For i As Integer = 1 To 10
|
||||
Console.WriteLine("{0} = {1}", i, CountingInFactors(i))
|
||||
Next
|
||||
|
||||
For i As Integer = 9991 To 10000
|
||||
Console.WriteLine("{0} = {1}", i, CountingInFactors(i))
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Function CountingInFactors(ByVal n As Integer) As String
|
||||
If n = 1 Then Return "1"
|
||||
|
||||
Dim sb As New Text.StringBuilder()
|
||||
|
||||
CheckFactor(2, n, sb)
|
||||
If n = 1 Then Return sb.ToString()
|
||||
|
||||
CheckFactor(3, n, sb)
|
||||
If n = 1 Then Return sb.ToString()
|
||||
|
||||
For i As Integer = 5 To n Step 2
|
||||
If i Mod 3 = 0 Then Continue For
|
||||
|
||||
CheckFactor(i, n, sb)
|
||||
If n = 1 Then Exit For
|
||||
Next
|
||||
|
||||
Return sb.ToString()
|
||||
End Function
|
||||
|
||||
Private Sub CheckFactor(ByVal mult As Integer, ByRef n As Integer, ByRef sb As Text.StringBuilder)
|
||||
Do While n Mod mult = 0
|
||||
If sb.Length > 0 Then sb.Append(" x ")
|
||||
sb.Append(mult)
|
||||
n = n / mult
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue