2012年9月12日 星期三

退休的福利


老瘋是楓智高中的校長,如今要退休了,楓智高中對退休有個特殊的傳統,就是第1天可以得到一顆米,而第二天可以得到2顆米,第3天可以再拿四顆米,.....請你求第N天共得多少米?N<=1000。

輸入說明 :
有個數N。
輸出說明 :
第N天共得多少米。

範例輸入 :

1



1000

範例輸出 :



10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069375

1 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Dim a(1000), ans2(1000)
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    a(1) = 1
    a(2) = 2
    a(3) = 4
    ans2(1) = 1
    ans2(2) = 3
    ans2(3) = 7
    ans = 7
    For i = 4 To 1000
    c = 0
    For j = Len(a(i - 1)) To 1 Step -1
    b = Val(Mid(a(i - 1), j, 1))
    d = b + b + c
    c = 0
    If d >= 10 And j <> 1 Then
    c = d \ 10
    d = d Mod 10
    a(i) = d & a(i)
    Else
    If d <> 0 Or j <> 1 Then a(i) = d & a(i)
    End If
    Next

    If Len(ans) <> Len(a(i)) Then
    Do
    If Len(ans) < Len(a(i)) Then ans = "0" & ans
    If Len(ans) > Len(a(i)) Then a(i) = "0" & a(i)
    Loop Until Len(ans) = Len(a(i))
    End If
    d = 0
    ans1 = ""

    For j = Len(ans) To 1 Step -1
    b = Val(Mid(a(i), j, 1))
    c = Val(Mid(ans, j, 1))
    e = b + c + d
    d = 0
    If e >= 10 And j <> 1 Then
    d = e \ 10
    e = e Mod 10
    ans1 = e & ans1
    Else
    If e <> 0 Or j <> 1 Then ans1 = e & ans1
    End If
    Next
    ans = ans1
    ans2(i) = ans
    Next

    Do While Not EOF(1)
    Input #1, n
    Print #2, ans2(n)
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除