Problem2:數字分解(11%)
Solomon
posted @ 2010年8月14日 03:22
in 98程式設計模擬試題
, 1306 阅读
Problem2:數字分解(11%)
給一個偶數 n,請你將 n 分解成兩個質數的和,也就是說,這兩個質數相加的和必須等於 n。輸入說明:第一行的數字,表示有幾組測試資料,第二行開始即為第一筆測試資料,每筆測試資料為一個數字,數字的範圍為[4, 10000]間的偶數。輸出說明:對輸入的每筆測試資料,分別輸出 2 個質數,用一個空白做為區隔,請由小到大排列。輸入範例:212100輸出範例:5 73 97
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim fileContents As String fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Test2.txt") Dim row() = Split(fileContents, vbNewLine) Dim str1 = "" For i As Integer = 0 To Val(row(0)) If row(i) = "" Then Exit For Dim k = Val(row(i)) For j As Integer = k - 1 To 1 Step -1 If f(k - j) = True And f(k - (k - j)) = True Then '條件:兩個都是質數 str1 = str1 & k - j & " " & k - (k - j) & vbNewLine Exit For End If Next Next My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\result2.txt", str1, False) End End Sub Function f(ByVal n) '質數判斷 Dim c = 0 Dim a = False For i As Integer = 1 To n If n Mod i = 0 Then c = c 1 Next If c = 2 Then a = True Return a End Function End Class
2022年12月05日 20:12
The 98 programming mock exam questions are designed to help you prepare for the actual programming exam. These questions cheap real diamond rings online will cover topics such as variables, data types, loops, and functions. Studying for this exam will give you a good foundation in programming concepts and help you better understand the material covered on the actual exam.
2022年12月28日 16:00
Programming mock tests are a great way to prepare for an upcoming programming test. These tests can help you become familiar with the types of questions that will be asked on the test, and they can also help you gauge your own level of knowledge and understanding. There are a variety of online resources that offer programming mock tests, so be sure to take advantage of diamond rings these tools to help you prepare for your upcoming test.