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 Input #1, x, y For i = 1 To x If x Mod i = 0 Then If i Mod y = 0 Then ans = ans + 1 End If Next Print #2, ans ans = 0 Loop While Not EOF(1) Close Close End End Sub
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 Input #1, x, y ans = 0 For i = 1 To x If x Mod i = 0 Then If i Mod y = 0 Then ans = ans + 1 End If Next i Print #2, ans Loop While Not EOF(1) Close #2 Close #1 End End Sub
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Input #1, x, y For i = 1 To x For j = 1 To x If i * j = x Then If j Mod y = 0 Then ans = ans + 1 End If Next j Next i Print #2, ans ans = 0 Loop While Not EOF(1) Close #2 Close #1 End End Sub
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
Input #1, x, y
For i = 1 To x
If x Mod i = 0 Then
If i Mod y = 0 Then ans = ans + 1
End If
Next
Print #2, ans
ans = 0
Loop While Not EOF(1)
Close
Close
End
End Sub
兩行之間若有空一行,則程式就會錯誤了,會影響到。
輸入:
36 2
64 8
輸出:
6
4
小冰好,
回覆刪除程式正確。
從舊題目中,選題出來時,如果覺得舊題目不正確,可以更改成新題目,將舊題目另外放在「舊題目參考」中。
另外,因為是網頁的方式,有些空白是不準確的,那倒是沒關係的。
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
Input #1, x, y
ans = 0
For i = 1 To x
If x Mod i = 0 Then
If i Mod y = 0 Then ans = ans + 1
End If
Next i
Print #2, ans
Loop While Not EOF(1)
Close #2
Close #1
End
End Sub
晟晟好,
回覆刪除程式正確。
你和小冰用的方式都很直覺。
先求第一個的因數,再看是不是能被第二個整除。
再想一想,有沒有更「數學」的解法呢?
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Input #1, x, y
For i = 1 To x
For j = 1 To x
If i * j = x Then
If j Mod y = 0 Then ans = ans + 1
End If
Next j
Next i
Print #2, ans
ans = 0
Loop While Not EOF(1)
Close #2
Close #1
End
End Sub