keytin's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 6 (0.07 per day)
- Joined:
- 22-February 13
- Profile Views:
- 21
- Last Active:
Feb 24 2013 02:59 AM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
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. -
In Topic: Odd composite number
Posted 22 Feb 2013
tlhIn`toq, on 22 February 2013 - 11:12 AM, said:We can't do anything to help you without your code.
this is my form, and exe file
tlhIn`toq, on 22 February 2013 - 11:12 AM, said:We can't do anything to help you without your code.
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
num += 3 + adj
adj = -adj
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
-
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
button try load..
If CheckPrime(txtinput.Text) Then
txtoutput.Text = ("prime")
Else
txtoutput.Text = ("odd")
End If
-----
Thankyou -
In Topic: Composite odd number
Posted 22 Feb 2013
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Click here to e-mail me
Friends
keytin hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
keytin has no profile comments yet. Why not say hello?