Private Sub Form_Load() Me.Hide Open App.Path & "\out.txt" For Output As #2 Open App.Path & "\in.txt" For Input As #1
Do Until EOF(1) Input #1, n
If n = 4 Then a = 2: b = 2 Else For i = n - 1 To 2 Step -1 If cc(i) = False Then If cc(n - i) = False Then a = i: b = n - i: Exit For End If Next End If Print #2, n & " = " & a & " + " & b Loop
Close #1 Close #2 End End Sub Function cc(a1) gm = False If a1 = 1 Then gm = True For i = 2 To a1 / 2 If a1 Mod i = 0 Then gm = True Next cc = gm End Function ----------------- in.txt 10 20 22 12 52 4 100 48 32 10000000 -----------------
Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do While Not EOF(1) Input #1, ans T = False Call ABC(ans, ans & "=") Loop Close #2 Close #1
End End Sub
Function ABC(A, B) If A = 0 Then Print #2, Left(B, Len(B) - 1): T = True Else For i = A To 2 Step -1 p = True For j = 2 To i - 1 If i Mod j = 0 Then p = False Next j If p = True Then If Mplus(B) <= 1 Then Call ABC((A - i), (B & i & "+")) If T = True Then Exit For End If Next i End If End Function
Function Mplus(A) For i = 1 To Len(A) If Mid(A, i, 1) = "+" Then ans = ans + 1 Next i Mplus = ans End Function
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
Input #1, n
For i = 2 To n
If i + (n - i) = n And Func(i) = True And Func(n - i) = True Then Print #2, n & " = " & i & " + " & (n - i): Exit For
Next
Loop
Close
Close
End
End Sub
Function Func(a)
k = True
For i = 2 To a / 2
If a Mod i = 0 Then k = False
Next
Func = k
End Function
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Do Until EOF(1)
Input #1, n
If n = 4 Then
a = 2: b = 2
Else
For i = n - 1 To 2 Step -1
If cc(i) = False Then
If cc(n - i) = False Then a = i: b = n - i: Exit For
End If
Next
End If
Print #2, n & " = " & a & " + " & b
Loop
Close #1
Close #2
End
End Sub
Function cc(a1)
gm = False
If a1 = 1 Then gm = True
For i = 2 To a1 / 2
If a1 Mod i = 0 Then gm = True
Next
cc = gm
End Function
-----------------
in.txt
10
20
22
12
52
4
100
48
32
10000000
-----------------
10 = 7 + 3
20 = 17 + 3
22 = 19 + 3
12 = 7 + 5
52 = 47 + 5
4 = 2 + 2
100 = 97 + 3
48 = 43 + 5
32 = 29 + 3
10000000 = 9999971 + 29
Dim T As Boolean
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
Input #1, ans
T = False
Call ABC(ans, ans & "=")
Loop
Close #2
Close #1
End
End Sub
Function ABC(A, B)
If A = 0 Then
Print #2, Left(B, Len(B) - 1): T = True
Else
For i = A To 2 Step -1
p = True
For j = 2 To i - 1
If i Mod j = 0 Then p = False
Next j
If p = True Then
If Mplus(B) <= 1 Then Call ABC((A - i), (B & i & "+"))
If T = True Then Exit For
End If
Next i
End If
End Function
Function Mplus(A)
For i = 1 To Len(A)
If Mid(A, i, 1) = "+" Then ans = ans + 1
Next i
Mplus = ans
End Function
-----------------
in.txt
10
20
22
12
52
4
100
48
32
10000000
-----------------
10 = 7 + 3
20 = 17 + 3
22 = 19 + 3
12 = 7 + 5
52 = 47 + 5
4 = 2 + 2
100 = 97 + 3
48 = 43 + 5
32 = 29 + 3
10000000 = 9999971 + 29
----------------------
一不小心做成
10=7+3
10=5+5
10=5+3+2
10=5+2+3
10=3+7
10=3+5+2
10=3+3+2+2
10=3+2+5
10=3+2+3+2
10=3+2+2+3
10=2+5+3
10=2+3+5
10=2+3+3+2
10=2+3+2+3
10=2+2+3+3
10=2+2+2+2+2
arro,緣尉,佑好,
回覆刪除3個程式都正確。
佑,如果在解題的過程式,發現可以做的類似題,那就再出一題,並寫出程式啊。
arro好,
回覆刪除上次有說過的
If i + (n - i) = n
這樣的多餘的動作,要小心些哦。