Единственно возможный вариант - длинная арифметика. Можешь почитать на http://algolist.manual.ru или посмотреть мой пример (он, правда, не факториал вычисляет, а степень числа, но разница невелика): VERSION 5.00 Begin VB.Form frmMain Caption = "C++" ClientHeight = 5760 ClientLeft = 60 ClientTop = 345 ClientWidth = 10785 BeginProperty Font Name = "Tahoma" Size = 8.25 Charset = 204 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Icon = "frmMain.frx":0000 LinkTopic = "Form1" ScaleHeight = 384 ScaleMode = 3 'Pixel ScaleWidth = 719 StartUpPosition = 3 'Windows Default Begin VB.Frame frameControl Caption = "Управление" Height = 615 Left = 120 TabIndex = 1 Top = 5040 Width = 10575 Begin VB.CommandButton cmdStart Caption = "OK" Default = -1 'True Height = 255 Left = 9600 TabIndex = 5 Top = 240 Width = 855 End Begin VB.TextBox txtNum Appearance = 0 'Flat Height = 285 Left = 8640 TabIndex = 4 Text = "5000" Top = 240 Width = 855 End Begin VB.TextBox txtBase Appearance = 0 'Flat Height = 285 Left = 7560 TabIndex = 3 Text = "2" Top = 240 Width = 855 End Begin VB.Label Label1 Alignment = 2 'Center Caption = "^" Height = 255 Left = 8400 TabIndex = 6 Top = 240 Width = 255 End Begin VB.Label lblProcess BackStyle = 0 'Transparent Caption = "Готово." ForeColor = &H00C00000& Height = 255 Left = 120 TabIndex = 2 Top = 240 Width = 7335 End End Begin VB.TextBox txtAnswer Appearance = 0 'Flat Height = 4815 Left = 120 Locked = -1 'True MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 0 Top = 120 Width = 10575 End End Attribute VB_Name = "frmMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Const A_S = 32767 Const BASE_SYSTEM = 10 Private Sub cmdStart_Click() On Error GoTo ErrDefine Dim a(A_S) As Long Dim Temp As Long Dim n As Long, i As Long, j As Long, u As Long, nd As Long, L1 As Double, BASE_NUMBER As Long Dim w1 As Single, w2 As Single Dim ans As String If cmdStart.Caption = "Отмена" Then cmdStart.Caption = "OK" lblProcess = "Готово." Exit Sub End If n = CLng(txtNum) BASE_NUMBER = IIf(CLng(txtBase) > 1, CLng(txtBase), 2) If BASE_NUMBER = 2 Then txtBase = 2 L1 = Log(BASE_NUMBER) / Log(BASE_SYSTEM) nd = IIf(BASE_NUMBER = BASE_SYSTEM ^ CLng(L1), Int(L1 * n) + 2, Int(L1 * n) + 1) lblProcess = "Число цифр в результате " & Str(nd) If nd > A_S Then MsgBox "Число цифр в ответе больше 32767. Увеличьте размер массива.", vbCritical + vbOKOnly, "Ошибка" Exit Sub End If cmdStart.Caption = "Отмена" txtAnswer = "" For i = 1 To A_S a(i) = 0 Next a(1) = 1 '----------------------------------------------------------------------------------------------------- w1 = Timer For i = 1 To n If Int(i / n * 10) > Int((i - 1) / n * 10) Then lblProcess = "Число цифр в результате " & Str(nd) & String(Int(i / n * 10), Asc(".")) DoEvents u = 0 q = Int(L1 * i) + 2 For j = 1 To q Temp = a(j) Temp = Temp * BASE_NUMBER + u u = 0 Do While Temp >= BASE_SYSTEM Temp = Temp - BASE_SYSTEM u = u + 1 Loop a(j) = Temp Next Next w2 = Timer '----------------------------------------------------------------------------------------------------- lblProcess = "Формирую результат..." DoEvents For i = nd To 1 Step -1 ans = ans & IIf(a(i) = 0, "0", Format(a(i), "#")) Next txtAnswer = ans lblProcess = "Готово. Затрачено " & Str(Int((w2 - w1) * 1000)) & " мс" cmdStart.Caption = "OK" Exit Sub ErrDefine: g = MsgBox("Произошла внутренняя ошибка" & vbCrLf & vbCrLf & "Номер ошибки: " & vbTab & CStr(Err.Number) & vbCrLf & "Описание: " & vbTab & CStr(Err.Description), vbAbortRetryIgnore + vbExclamation, "Внутренняя ошибка") Select Case g Case vbAbort: End Case vbRetry: Resume Case vbIgnore: Resume Next End Select End Sub Private Sub Form_Resize() If Me.WindowState <> vbMinimized Then If Me.Width < 4500 Then Me.Width = 4500 If Me.Height < 1800 Then Me.Height = 1800 txtAnswer.Width = Me.ScaleWidth - 14 txtAnswer.Height = Me.ScaleHeight - 57 frameControl.Top = Me.ScaleHeight - 48 frameControl.Width = Me.ScaleWidth - 14 txtBase.Lef
Ответить
|