算法思想:
首先生成一个比p大的全1数a,如果a能整除p,则算法结束,否则继续扩大a的位数,如此继续,直至a整除p。
程序运行界面如下图所示,在文本框Text1中输入整数p,单击“计算”按钮,在文本框Text2中输出整数s,在文本框Text3中输出乘积中1的个数。
小明依据上述描述设计如下VB程序。请回答下列问题:
Private Sub Command1_Click()
Dim p As Long, a As Long, b As Long, c As Long, n As Long
Dim s As String '存放整数s,因为该数较大,因此采用字符串存储
Do While True '判断输入的整数p是否为个位不是5的奇数
p = Val(Text1.Text)
If p Mod 2 < > 0 And p Mod 5 < > 0 Then Exit Do
Loop
a = 0
n = 0
Do While a < p
n = n + 1
Loop
c = a Mod p
s = Str(a \ p)
Do While c < > 0
a = c * 10 + 1
s = s & b
n = n + 1
Loop
Text2.Text = s
Text3.Text = Str(n)
End Sub