level 8
生成一个随机数:n=int(rnd*101)+100
用Function写一个N!
Private Function jc(N As integer) as Long
if n= 0 or n=1 then
JC=1 :exit function
end if
jc(n)=n*jc(n-1)
End Function
n取n-1、n、n+1 进行调用,楼主编写
2024年04月27日 06点04分
2
这题就算你用Double也可能溢出啊,居然用Long
2024年04月27日 07点04分
@初音✨七奈 是的,忘记考虑N的值很大,这个题不合理.
2024年04月27日 14点04分
@tbzp666 jc(n)=n*jc(n-1)改为jc=n*jc(n-1)
2024年05月03日 11点05分
吧务
level 14
分成两部分:第一部分:编写计算阶乘的函数。第二部分:第一步,生成随机数
使用int(rnd * 差值+1)+基值;第二步,调用阶乘函数
2024年04月27日 06点04分
3
吧务
level 12
n! = n * (n - 1)!
(n+1)! = (n+1)*n!
所以计算 (n - 1)! + n! + (n+1)!
= (n-1)! + n*(n-1)! + (n+1)*n*(n-1)!
=(1+ n + n^2+n) * (n - 1)!
=(n^2+2n+1)*(n-1)!
=(n+1)^2*(n-1)!
接下来就是实现 n! 的大数算法,可以基于字符串进行大整数乘法计算。
这才是挑战高的地方。但是你如果静下心来,也不是那么复杂。毕竟,你试试自己列竖式计算两个大数的乘法,就会发现步骤其实并不多。
2024年04月29日 14点04分
8
字符串可以达到把数字每一位都表示出来的极高精确度,对于这里的场合就是最多为201的阶乘的378位数;如果不需要达到如此高的精度,可以像6楼那样对科学计数法表示形式的指数部分做一个处理,一般Double的15位精度也就够用了
2024年04月29日 16点04分
大数怎么做,给个完整程序求N!,学习一下
2024年04月29日 23点04分
吧务
level 12
大数计算
```vb
Function MultiplyBigIntegers(ByVal strNum1 As String, ByVal strNum2 As String) As String
' Pad shorter string with zeros
If Len(strNum1) < Len(strNum2) Then strNum1 = String(Len(strNum2) - Len(strNum1), "0") & strNum1
If Len(strNum2) < Len(strNum1) Then strNum2 = String(Len(strNum1) - Len(strNum2), "0") & strNum2
Dim result As String
Dim carry As Integer
' Iterate through digits
For i = Len(strNum2) - 1 To 0 Step -1
Dim temp As String
carry = 0
For j = Len(strNum1) - 1 To 0 Step -1
Dim product As Integer
product = CInt(Mid(strNum1, j + 1, 1)) * CInt(Mid(strNum2, i + 1, 1)) + carry
carry = product \ 10 ' Integer division for carry
temp = CStr(product Mod 10) & temp ' Remainder for current digit
Next j
If carry > 0 Then temp = CStr(carry) & temp
result = String(Len(strNum2) - i - 1, "0") & temp + result
Next i
' Remove leading zeros
Do While Left(result, 1) = "0" And Len(result) > 1
result = Mid(result, 2)
Loop
MultiplyBigIntegers = result
End Function```
2024年04月30日 01点04分
9
得出的结果不对,比如80*90
2024年05月06日 07点05分
@klimaa AI生成的,有错误正常,改改应该可以用。
2024年05月06日 10点05分
level 9
回复 #(reply,tb.1.edd0c82c.RnFVYgFA04ZCjnEy5YYjBA,sunruisunrui) : 原来AI生成的这么不靠谱。我一直以为AI是到处抄,但是看这个代码真的有智慧在里面了,就像个学生学了之后自己写的。但是这个思路进位处理很困难。以后看代码不能看新的了。
2024年05月07日 05点05分
10