求2--1000中,每个数有多少个不同的质因子,并要求输出如下的式子:2=2 3=3 4=2*2 ...100=2*2*5*5 用记事本编程vb语言急用
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/17 01:15:40
![求2--1000中,每个数有多少个不同的质因子,并要求输出如下的式子:2=2 3=3 4=2*2 ...100=2*2*5*5 用记事本编程vb语言急用](/uploads/image/z/5297139-27-9.jpg?t=%E6%B1%822--1000%E4%B8%AD%2C%E6%AF%8F%E4%B8%AA%E6%95%B0%E6%9C%89%E5%A4%9A%E5%B0%91%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E8%B4%A8%E5%9B%A0%E5%AD%90%2C%E5%B9%B6%E8%A6%81%E6%B1%82%E8%BE%93%E5%87%BA%E5%A6%82%E4%B8%8B%E7%9A%84%E5%BC%8F%E5%AD%90%EF%BC%9A2%3D2+3%3D3+4%3D2%2A2+...100%3D2%2A2%2A5%2A5+%E7%94%A8%E8%AE%B0%E4%BA%8B%E6%9C%AC%E7%BC%96%E7%A8%8Bvb%E8%AF%AD%E8%A8%80%E6%80%A5%E7%94%A8)
求2--1000中,每个数有多少个不同的质因子,并要求输出如下的式子:2=2 3=3 4=2*2 ...100=2*2*5*5 用记事本编程vb语言急用
求2--1000中,每个数有多少个不同的质因子,并要求输出如下的式子:
2=2
3=3
4=2*2
...
100=2*2*5*5
用记事本编程
vb语言
急用
求2--1000中,每个数有多少个不同的质因子,并要求输出如下的式子:2=2 3=3 4=2*2 ...100=2*2*5*5 用记事本编程vb语言急用
Rem 大家看你一分也不给,都不来搭理你哈,小女子发扬一下助人为乐的奉献精神吧
Rem 窗体建一个Text1,一个Text2,MultiLine属性改为True,ScrollBars设置为2(垂直滚动条)
Option Explicit
Private Function isprime(Num As Long) As Boolean
If Num < 2 Then isprime = False:Exit Function
Dim i As Long
For i = 2 To Sqr(Num)
If (Num Mod i) = 0 Then
isprime = False
Exit Function
End If
Next i
isprime = True
End Function
Private Sub Form_Click()
Dim i As Long,j As Long,temp As Long,diff As Long
Dim primestr(2 To 1000) As String,nall(2 To 1000) As Integer,ndiff(2 To 1000) As Integer
'primestr存放质因子的分解因式,nall存放质因子总的数目,ndiff存放不同质因子的数目
Cls
Text1 = ""
Text2 = ""
For i = 2 To 1000
Print i & "=";
primestr(i) = i & "="
nall(i) = 0:ndiff(i) = 0
temp = i
If Not isprime(temp) Then
j = 2
diff = 0
Do While Not isprime(temp)
If temp Mod j = 0 Then
Print j & "*";
primestr(i) = primestr(i) & j & "*"
nall(i) = nall(i) + 1
If diff j Then ndiff(i) = ndiff(i) + 1:diff = j
temp = temp \ j
Else
Do
j = j + 1
Loop Until isprime(j)
End If
Loop
If isprime(temp) And temp j Then ndiff(i) = ndiff(i) + 1
Else
ndiff(i) = 1
End If
Print CStr(temp)
primestr(i) = primestr(i) & CStr(temp) & vbCrLf
nall(i) = nall(i) + 1
Next
'输出不同质因子的数目
'For i = 2 To 1000
'Text1 = Text1 & i & ":" & ndiff(i) & vbCrLf
'Next
'在Text2中输出分解因式,这个有点慢哈,1000个数太多了
'For i = 2 To 1000
'Text2 = Text2 & primestr(i)
'Next
End Sub