2012年11月5日 星期一

因數


已知兩個整數nd,請你找出n這個值,會有多少個因數可以被d整除。

輸入說明:

每組輸入包含兩個以空白隔開的數字nd,其n ( 0 < n < 1000000 ),而d ( 2 ≤ d < 1000 )
輸出說明:
對於每組測試資料,輸出n這個值,會有多少個因數可以被d整除。
輸入範例:
36 2
64 8
輸出範例:
6
4

6 則留言:

  1. 作者已經移除這則留言。

    回覆刪除
  2. 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)
    ans = 0
    Input #1, n, d
    For i = 2 To n
    If n Mod i = 0 Then
    If i Mod d = 0 Then ans = ans + 1
    End If
    Next
    Print #2, ans
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除
  3. Dim num1, num2, ans As Integer
    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, num1, num2
    For i = 1 To num1
    If num1 Mod i = 0 Then
    If i Mod num2 = 0 Then ans = ans + 1
    End If
    Next
    Print #2, ans
    ans = 0
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  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 Until EOF(1)
    t = 0
    Input #1, a, b
    For i = 1 To a
    If a Mod i = 0 And i Mod b = 0 Then t = t + 1
    Next
    Print #2, t
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除
  5. 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, d
    For i = 2 To n
    If n Mod i = 0 Then
    If i Mod d = 0 Then ans = ans + 1
    End If
    Next
    Print #2, ans
    Close
    Close
    End
    End Sub

    回覆刪除