For i = 10 To 99 a = i \\ 10 b = i Mod 10 x = 0
For j = 2 To Sqr(i)
If i Mod j = 0 Then x = 1: Exit For Next j
If x = 0 Then y = 0
c = b * 10 + a
For j = 2 To Sqr(c)
If c Mod j = 0 Then y = 1: Exit For Next j
If y = 0 Then s = s + i End If Next i Print s
12. 在[200,900]范围 内同时满足以下两个条件的十进制数:⑴其个位数字与十位数字之和除以10所得的余数是百位数字; ⑵该数是素数;问有多少个这样的数? 14 n = 0
For i = 200 To 900 a = i \\ 100
b = i \\ 10 Mod 10 c = i Mod 10
If (c + b) Mod 10 = a Then x = 0
For j = 2 To i - 1
If i Mod j = 0 Then x = 1: Exit For Next j
If x = 0 Then n = n + 1 End If Next i Print n
13. 一个素数,依次从个位开始去掉一位,二位.....,所得的各数仍然是素数,称为超级素数。求[100,999]之内超级素数的个数。 14 n = 0
For i = 100 To 999 x = 0
For j = 2 To Sqr(i)
If i Mod j = 0 Then x = 1: Exit For Next j
If x = 0 Then a = i \\ 10
第 6 页
y = 0
For j = 2 To Sqr(a)
If a Mod j = 0 Then y = 1: Exit For Next j
If y = 0 Then b = i \\ 100 If b <> 1 Then z = 0
For j = 2 To Sqr(b)
If b Mod j = 0 Then z = 1: Exit For Next j
If z = 0 Then n = n + 1 End If End If End If Next i Print n
14. 若两个连续的自然数的乘积减1后是素数,则称此两个连续自然数为友数对,该素数称为友素数。例如,由于 8*9-1=71, 因此,8与9是友素数对,71是友素数。求[100,200]之间的第10个友素数对所对应的友素数的值(按由小到大排列)。 17291 For i = 100 To 199 a = i * (i + 1) - 1 x = 0
For j = 2 To Sqr(a)
If a Mod j = 0 Then x = 1: Exit For Next j
If x = 0 Then n = n + 1
If n = 10 Then s = a End If Next i Print s
15. 求[2,400]中相差为10的相邻素数对(两数中间没有其它素数)的对数。 5 n = 0
For I = 2 To 400 - 10 x = 0
For j = 2 To Sqr(I)
If I Mod j = 0 Then x = 1: Exit For Next j
If x = 0 Then y = 0
For j = 2 To Sqr(I + 10)
If (I + 10) Mod j = 0 Then y = 1: Exit For Next j
第 7 页
If y = 0 Then
For k = I + 1 To I + 9 z = 0
For k1 = 2 To Sqr(k)
If k Mod k1 = 0 Then z = 1: Exit For Next k1
If z = 0 Then Exit For Next k
If k = I + 10 Then n = n + 1 End If End If Next I Print n
16. 若两个连续的自然数的乘积减1后是素数,则称此两个连续自然数为友数对,该素数称为友素数。例如,由于 8*9-1=71, 因此,8与9是友数对,71是友素数。求[50,150]之间的友数对的数目。38 n = 0
For i = 50 To 150 a = i * (i + 1) - 1 x = 0
For j = 2 To Sqr(a)
If a Mod j = 0 Then x = 1: Exit For Next j
If x = 0 Then n = n + 1 End If Next i Print n
17. 若两个连续自然数乘积减1后是素数,则称此两个自然连续数为友数对,该素数称为友素数,例:2*3-1=5,因此2与3是友数对,5是友素数,求[40,119]之间友素数对的数目。 30 n = 0
For i = 40 To 119 a = i * (i + 1) - 1 x = 0
For j = 2 To Sqr(a)
If a Mod j = 0 Then x = 1: Exit For Next j
If x = 0 Then n = n + 1 End If Next i Print n
18. 梅森尼数是指能使2^n-1为素数的数n,求[1,21]范围内有多少个梅森尼数? 7
第 8 页
n = 0
For i = 2 To 21 x = 2 ^ i - 1 k = 0
For j = 2 To Sqr(x)
If x Mod j = 0 Then k = 1 Next j
If k = 0 Then n = n + 1 Next i Print n
19. [300,800]范围内同时满足以下两个条件的十进制数. ⑴其个位数字与十位数字之和除以10所得的余数是百位数字 ;⑵该数是素数;求满足上述条件的最大的三位十进制数。 761 For i = 300 To 800 a = i \\ 100
b = i \\ 10 Mod 10 c = i Mod 10
If (c + b) Mod 10 = a Then k = 0
For j = 2 To Sqr(i)
If i Mod j = 0 Then k = 1 Next j
If k = 0 Then s = i End If Next i Print s
2. 取数字
20. 求符合下列条件的四位完全平方数(某个正整数A是另一个正整数B的平方,则称A为完全平方数),它的千位数字与十位数字之和等于百位数字与个位数字之积,例如,3136=562, 且3+3=1*6 故3136是所求的四位完全平方数. 求其中最大的一个数。 7921 For i = 1000 To 9999 x = Sqr(i)
If x = Int(x) Then a = i \\ 1000
b = i \\ 100 Mod 10 c = i \\ 10 Mod 10 d = i Mod 10
If (a + c) = b * d Then s = i End If Next i Print s
第 9 页
21.设某四位数的千位数字平方与十位数字的平方之和等于百位数字的立方与个位数字的立方之和,例如,对于四位数:3201, 3^2+0^2=2^3+1^3,试问所有这样的四位数之和是多少?97993 s = 0
For i = 1000 To 9999 a = i \\ 1000
b = i \\ 100 Mod 10 c = i \\ 10 Mod 10 d = i Mod 10
If (a ^ 2 + c ^ 2) = b ^ 3 + d ^ 3 Then s = s + i Next i Print s
22. 设某四位数的千位数字与十位数字的和等于百位数字与个位数字的积,例如,对于四位数:9512,9+1=5*2,试问所有这样的四位数之和是多少? 1078289 s = 0
For i = 1000 To 9999 a = i \\ 1000
b = i \\ 100 Mod 10 c = i \\ 10 Mod 10 d = i Mod 10
If (a + c) = b * d Then s = s + i Next i Print s
23. 有一个三位数满足下列条件: (1)此三位数的三位数字各不相同; (2)此三位数等于它的各位数字的立方和。试求所有这样的三位数之和。 1301 s = 0
For i = 100 To 999 a = i \\ 100
b = i \\ 10 Mod 10 c = i Mod 10
If (a ^ 3 + b ^ 3 + c ^ 3) = i And a <> b And b <> c And c <> a Then s = s + i Next i Print s
24. 求[1,999]之间能被3整除,且至少有一位数字是5的所有正整数的个数。 91 n = 0
For i = 1 To 999 a = i \\ 100
b = i \\ 10 Mod 10 c = i Mod 10
If i Mod 3 = 0 And (a = 5 Or b = 5 Or c = 5) Then n = n + 1 Next i Print n
第 10 页