| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 31769 人关注过本帖
标题:各位老师好!求助编辑一个大整数的快速乘除法可调用程序
只看楼主 加入收藏
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
回复 20楼 wmf2014
只要个总个数,不用打表,10^10内的。我都算了好几天了,10^9~10^10之间的都没有算出来,是朋友要这个数据的。谢谢您!祝您身体健康万事如意!
2020-02-12 10:13
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
Copyright © 1999-2020, , All Rights Reserved



搜索博文/帖子/用户
 登录
VB实现FFT算法 转载

weixin_34245749

225次阅读 2013-04-17

关注
程序列如下:

Public Function fft(ByRef Data() As Double) As Double()
    ReDim ffft(128, 2) As Double
    Dim length As Integer
    length = UBound(Data, 1) + 1
'    Dim numArray(length - 1, 2) As Double
      
    Dim index As Integer
    Dim num5 As Integer
    Dim num6 As Integer
    Dim num7 As Integer
    Dim num10 As Integer
    Dim num3 As Integer
    Dim num2 As Integer
    Dim num11 As Integer
    Dim num9 As Integer
    num9 = length
      
    Dim num8 As Integer
    num8 = CInt(Math.Log(CDbl(num9)) / Math.Log(2#))
      
    Dim numArray2(128) As Double
    Dim numArray3(128) As Double
    Dim numArray4(128) As Double
    Dim numArray5(128) As Double
    For index = 0 To num9 - 1
        numArray2(index) = Data(index)
        numArray3(index) = 0#
    Next
    Dim a As Double
    Dim num14 As Double
      
   num14 = 6.28318530717959 / CDbl(num9)
    index = 0
    While index < (num9 \ 2)
        numArray4(index) = Math.Sin(a)
        numArray5(index) = Math.Cos(a)
        a = a + num14
        index = index + 1
    Wend
    num7 = num9
    num3 = 1
    For num2 = 1 To num8
        num7 = num7 / 2
        num6 = 0
        For num11 = 1 To num3
            num10 = 0
            index = num6
            While index <= ((num7 + num6) - 1)
                num5 = index + num7
                a = numArray2(index) - numArray2(num5)
                num14 = numArray3(index) - numArray3(num5)
                numArray2(index) = numArray2(index) + numArray2(num5)
                numArray3(index) = numArray3(index) + numArray3(num5)
                If num10 = 0 Then
                    numArray2(num5) = a
                    numArray3(num5) = num14
                Else
                    numArray2(num5) = (a * numArray5(num10)) + (num14 * numArray4(num10))
                    numArray3(num5) = (num14 * numArray5(num10)) - (a * numArray4(num10))
                End If
                num10 = num10 + num3
                index = index + 1
           Wend
            num6 = (num6 + num7) + num7
        Next
        num3 = num3 + num3
    Next
    num5 = num9 \ 2
    For index = 1 To (num9 - 1)
        num6 = num9
        If num5 < index Then
            Dim num12 As Double
              
          num12 = numArray2(index)
            numArray2(index) = numArray2(num5)
            numArray2(num5) = num12
            num12 = numArray3(index)
            numArray3(index) = numArray3(num5)
            numArray3(num5) = num12
        End If
        num6 = num6 / 2
        Do While num5 >= num6
            num5 = num5 - num6
            num6 = num6 / 2
            If num5 = 0 Then
                Exit Do
            End If
        Loop
        num5 = num5 + num6
    Next
    For index = 0 To num9 - 1
        numArray(index, 0) = numArray2(index)
        numArray(index, 1) = numArray3(index)
        numArray(index, 2) = ((numArray2(index)) ^ 2# + (numArray3(index)) ^ 2#) ^ 0.5
    Next
   fft = numArray
End Function

前面的程序的说明(原稿中复制过来的):
默认了数组为128
如果你需要动态,请
redim各数组

输入:一串数据
输出:FFT变换后的数据,1维是实部 ,2维是虚部

这是vb版快速傅立叶变换fft,不懂,也不知道输出啥结果,不知道是否可以用于大整数的快速乘法。

没有找到vb版的大整数快速乘法程序。

有vc版的,不懂。
2020-02-12 10:54
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
是不是输出素数占用了时间,不输出素数仅输出总个数就会快了?
2020-02-12 11:33
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
前面的这个程序如何调用?想试试能出啥结果,不知道如何用?
2020-02-12 13:38
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
找到一个vb程序,不知道是不是快速乘法程序,原文前面的是高精度vc版乘法程序,不懂,后面是这个程序,不知道是不是乘法程序。
Dim i, j, L(2), a(1000) As Integer, b(1000) As Integer, c(2000, 2000) As Integer, d(2000, 2000) As Integer, x(10000) As Integer, jieguo As String, y(10000) As Integer

Private Sub Command1_Click()

L(1) = Len(Text2.Text)

L(2) = Len(Text3.Text)

For i = 1 To L(1)

a(i) = Val(Mid(Text2.Text, L(1) - i + 1, 1))

Next i

For i = 1 To L(2)

b(i) = Val(Mid(Text3.Text, L(2) - i + 1, 1))

Next i

For i = 1 To L(2)

For j = 1 To L(1)

c(i, j) = b(i) * a(j) + c(i, j)

d(i, j) = Int(c(i, j) / 10)

If d(i, j) > 0 Then

c(i, j) = c(i, j) - 10 * d(i, j)

c(i, j + 1) = c(i, j + 1) + d(i, j)

End If

d(i, j) = 0

Next j

Next i

For i = 1 To L(2)

b(i) = 0

Next i

For i = 1 To L(1)

a(i) = 0

Next i

For i = 1 To L(2)

For j = 1 To L(1) + 1

x(i + j - 1) = x(i + j - 1) + c(i, j)

c(i, j) = 0

Next j

Next i

For i = 1 To L(1) + L(2) + 1

y(i) = Int(x(i) / 10)

If y(i) > 0 Then

x(i) = x(i) - 10 * y(i)

x(i + 1) = x(i + 1) + y(i)

End If

y(i) = 0

Next i

Text1.Text = ""

If x(L(1) + L(2) + 1) <> 0 Then Text1.Text = Text1.Text & x(L(1) + L(2) + 1)

If x(L(1) + L(2)) <> 0 Then Text1.Text = Text1.Text & x(L(1) + L(2))

For i = L(1) + L(2) - 1 To 1 Step -1

Text1.Text = Text1.Text & x(i)

Next i

For i = 1 To L(1) + L(2) + 1

x(i) = 0

Next i

L(1) = 0

L(2) = 0

jieguo = Text1.Text

End Sub

Private Sub Form_Load()

Text2.Text = "a"

Text3.Text = "b"

Text1.Text = "结果"

Command1.Caption = "计算"

Timer1.Interval = 1

"interval,是间隔,值只能为数字而不能是true

jieguo = "结果"

End Sub

Private Sub Timer1_Timer()

Text1.Text = jieguo

End Sub

经过我验证了一下,这个乘法的速度不快,还没有我的模仿手工计算的乘法速度快,且大整数超过不知道多少位就会下标越界。太大话不能用了。

[此贴子已经被作者于2020-2-12 17:57编辑过]

2020-02-12 16:47
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
这个也是写着是分治法乘法,不知道是不是,不知道怎么用?咋弄?
Function Mult_() '分治法   多位数相乘  C*A=C,A 2013-06.14
Dim myVar, myNum, Var, r As Variant
Dim Aa, Ba, Ca, xP2 As Single
Dim Dx As Chen
Dim ax_sz(512), bx_sz(512), cx_sz(512) As Variant
        
Ax.St = Ax.St + Zero
Cx.St = Cx.St + Zero

If Left(Ax.St, 1) > "0" And Left(Cx.St, 1) > "0" Then
    For i = 0 To xP
        ax_sz(i) = CDec(Mid(Ax.St, i * Gsw + 1, Gsw))
        bx_sz(i) = CDec(Mid(Cx.St, i * Gsw + 1, Gsw))
    Next i

    myVar = ax_sz(0) * bx_sz(0)
    cx_sz(1) = myVar
    For i = 1 To xP
       myNum = ax_sz(i) * bx_sz(i)
       myVar = myVar + myNum
       For j = 0 To (i - 1) / 2
        cx_sz(i + 1) = cx_sz(i + 1) + (ax_sz(i - j) - ax_sz(j)) * (bx_sz(j) - bx_sz(i - j))
       Next
       cx_sz(i + 1) = cx_sz(i + 1) + myVar
    Next
   
   r = CDec(0)
For i = xP To 0 Step -1
    cx_sz(i) = cx_sz(i) + r
    r = Fix(cx_sz(i) / Zero6)
    cx_sz(i) = cx_sz(i) - r * Zero6
Next i

oResult = CStr(cx_sz(0))
For i = 1 To xP
    oResult = oResult + Right(Zero06 + CStr(cx_sz(i)), Gsw)
Next i

Dx.Bz = IIf(Ax.Bz = Cx.Bz, "", "-")
Dx.St = oResult

'指数计算
Aa = Val(Left(Ax.St, 1))
Ba = Val(Left(Cx.St, 1))
Ca = Val(Left(Dx.St, 1))

If Ax.Zs + Cx.Zs < 10 ^ 15 Then
    Dx.Zs = Ax.Zs + Cx.Zs + IIf(Aa * Ba <= Ca, 0, 1)
Else
    Dx.Zs = 0
End If

Cx = Dx
Ax = Dx

Else
   Ax.Bz = ""
   Ax.St = "0"
   Ax.Zs = 0
   Cx = Ax
End If
End Function
2020-02-12 16:50
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
收藏
得分:0 
用excel vba打16(1.6×10^10)亿内素数表,共用时5分钟,有点慢,用c只需要13秒,vba代码如下:
程序代码:
Dim pri(200000000) As Byte

Sub 按钮1_Click()
  pritab
End Sub

Sub pritab()
  '用字节位筛法生成16亿以内的素数表
  Dim i As Long, j As Long, b(8) As Byte, c As Byte, k As Long, l As Long, t As Double
  j = 1
  t = Timer
  For i = 0 To 7
    b(i) = j
    j = j * 2       '位运算值初始化
  Next
  For i = 0 To 200000000
    pri(i) = 170    '先假设所有奇数都是素数
  Next
  pri(0) = 172      '0,1不是素数,2是素数
  i = 3
  While i * i <= 1600000000
    If (pri(Int(i / 8)) And b(i Mod 8)) > 0 Then
      j = i * i
      While j <= 1600000000
        If (pri(Int(j / 8)) And b(j Mod 8)) > 0 Then
          c = b(j Mod 8) Xor 255
          pri(Int(j / 8)) = pri(Int(j / 8)) And c
        End If
        j = j + i * 2
      Wend
    End If
    i = i + 2
  Wend
  k = 0
  j = 0
  For i = 2 To 1600000000
    If (pri(Int(i / 8)) And b(i Mod 8)) > 0 Then
      If i - l = 2 Then j = j + 1
      k = k + 1
      l = i
    End If
  Next
  MsgBox "总素数:" & k & ",最大素数:" & l & ",孪生素数对:" & j & ",用时:" & Timer - t & ""
End Sub



运行效果如下:
图片附件: 游客没有浏览图片的权限,请 登录注册

能编个毛线衣吗?
2020-02-12 19:13
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
嗯,谢谢!您这个是1.6*10^10内的吧?这个是vba程序?我能用吗?谢谢!我试试吧!
太好了,谢谢,非常感谢!祝您新年快乐万事如意,身体健康阖家幸福安康!
2020-02-12 20:23
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
是1.6*10^9吧?看你程序中的数字的位数是10位的
2020-02-12 20:28
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
我的程序到现在还没有算到这么大呢。
2020-02-12 20:29
快速回复:各位老师好!求助编辑一个大整数的快速乘除法可调用程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029032 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved