## keytin's Profile User Rating:

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
6 (0.01 per day)
Joined:
22-February 13
Profile Views:
175
Last Active:
Feb 24 2013 02:59 AM
Currently:
Offline

### Previous Fields

Dream Kudos:
0
keytin has not set their status

1. #### In Topic: Odd composite number

Posted 22 Feb 2013

jon.kiparsky, on 22 February 2013 - 11:30 AM, said:

Why have you opened this duplicate topic?

oh, sorry.. I can't work out with this problem. I tried to make a new project but It didn't work. so I decided to open a new topic regarding my problem, hoping that someone can help me/ give me an idea or what I am suppose to do.
2. #### In Topic: Odd composite number

Posted 22 Feb 2013

tlhIn`toq, on 22 February 2013 - 11:12 AM, said:

this is my form, and exe file

tlhIn`toq, on 22 February 2013 - 11:12 AM, said:

Public Class Form1
Public Shared Function NotSternParts(ByVal q As Long) As Long()
Dim p As Long = 2
Do While p < q
Dim test As Long = 0
Dim b As Long = 0
Do While test < q
b += 1
test = p + 2 * b * b
If test = q Then Return {p, b}
Loop
p = NextPrime(p)
Loop
Return {0L, 0L} 'Note: zero followed by lower case "L"
End Function
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim checkNumber As Long
If Not Long.TryParse(txtinp.Text, checkNumber) Then
MessageBox.Show("Enter a valid integer")
Exit Sub
End If
Dim parts() As Long = NotSternParts(checkNumber)
If parts(0) = 0 Then
txtres.Text = "ODD integers only!"
Else
txtres.Text = checkNumber.ToString & " = " & parts(0).ToString & " + 2 * " & parts(1).ToString & " ^ 2"
End If
End Sub

Public Shared Function NextPrime(ByVal num As Long) As Long
If num < 3 Then Return If(num < 2, 2, 3)

Dim adj As Integer = If((num + 1) Mod 6 < 2, -1, 1)
num = ((num + 1) \ 6) * 6 + adj 'Prime numbers > 3 must be 6k +/- 1

Do
Loop Until IsPrime(num)

Return num
End Function

Public Shared Function IsPrime(ByVal num As Long) As Boolean
If num < 9 Then
If num < 2 Then Return False
If num < 4 Then Return True
If num Mod 2 = 0 Then Return False
Return True
ElseIf num Mod 2 = 0 Then
Return False
End If
If num Mod 3 = 0 Then Return False

Dim maxFactor As Long = CLng(Math.Floor(Math.Sqrt(num)))
Dim factor As Long = 5
Do While factor <= maxFactor
If num Mod factor = 0 Then Return False
If num Mod (factor + 2) = 0 Then Return False
factor += 6
Loop

Return True
End Function
End Class

--
I can't upload my .exe file..
that's my code. I Hope you can help me
3. #### In Topic: Composite odd number

Posted 22 Feb 2013

Ryano121, on 22 February 2013 - 08:19 AM, said:

a mod b gets you the remainder when a is divided by two. Using 2 instead of b will allow you to figure out if a number is odd or not.

Combine that with a check to figure out if the number is prime and you have your answer.

I thinnk, I got it check this if it is correct (hoping )

Private Function CheckPrime(ByVal no As Long) As Boolean
no = textinput.Text
If num Mod 2 = 0 Then
Return False
End If
For i = 3 To num / 2 + 1 Step 2
If num Mod i = 0 Then
Return False
End If
Next
Return True
End Function

If CheckPrime(txtinput.Text) Then
txtoutput.Text = ("prime")
Else
txtoutput.Text = ("odd")
End If

-----
Thankyou
4. #### In Topic: Composite odd number

Posted 22 Feb 2013

jon.kiparsky, on 22 February 2013 - 08:20 AM, said:

I'm not going to be able to help you with VB, but mathematically this question doesn't make any sense. There are an infinite number of composite odd numbers - which ones do you want?

odd composite number upto 10,000

Member Title:
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

E-mail: