2012年4月28日 星期六

因數


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

4 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Dim x, y, ans As Double
    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, 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
    Print #2, ans
    Loop
    Close
    Close
    End
    End Sub

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

    回覆刪除
  3. 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, x, y
    ans = 0
    For i = 2 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
    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 While Not EOF(1)
    ans = 0
    Input #1, a, b
    For i = 1 To Val(a)
    If Val(a) Mod Val(i) = 0 Then
    If Val(i) Mod Val(b) = 0 Then ans = ans + 1
    End If
    Next i
    Print #2, ans
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除