2012年9月5日 星期三

棋盤


在棋盤中放稻子
第一格放1個,第2格放2個,第3格放4個....以此類推
到第64個總共有幾個 ?

1 則留言:

  1. Dim ans
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #1
    For i = 0 To 48
    a = 2 ^ i
    ans = ans + a
    Next
    d = 0
    For i = 48 To 63
    e = ""
    For j = Len(a) To 1 Step -1
    b = Val(Mid(a, j, 1))
    c = b + b + d
    d = 0
    If c >= 10 And j <> 1 Then
    d = c \ 10
    c = c Mod 10
    End If
    e = c & e
    Next
    a = e
    d = 0
    e = ""
    Do
    If Len(a) < Len(ans) Then a = "0" & a
    If Len(ans) < Len(a) Then ans = "0" & ans
    Loop Until Len(ans) = Len(a)
    For j = Len(a) To 1 Step -1
    b = Val(Mid(a, j, 1))
    c = b + b + d
    d = 0
    If c >= 10 And j <> 1 Then
    d = c \ 10
    c = c Mod 10
    End If
    e = c & e
    Next
    Next
    Print #1, e
    Close
    End
    End Sub

    輸出是: 36893488147419103232

    回覆刪除