過去ログ

???
Cマガジンの01年10月号の電脳クラブと似た問題でした。
でもエクセルのマクロだと以下の通り。
Option Explicit
Sub Macro1()
Sheets("Sheet1").Select
Cells(1, 1).Value = 0
Dim a(10) As Integer
a(10) = 0
Call check(1, a())
End Sub
Sub check(ByVal n As Integer, ByRef a() As Integer)
Dim amari As Integer
Dim j As Integer
a(n) = 1
While a(n) <= 9
If onaji(n, a()) = 0 Then
amari = 0
For j = 1 To n
amari = (amari * 10 + a(j)) Mod n
Next j
If amari = 0 Then
If n < 9 Then
Call check(n + 1, a())
Else
Cells(1, 1).Value = Cells(1, 1).Value + 1
For j = 1 To 10
Cells(Cells(1, 1).Value, j + 1).Value = a(j)
Next j
End If
End If
End If
a(n) = a(n) + 1
Wend
End Sub
Private Function onaji(ByVal n As Integer, ByRef a() As Integer) As Integer
Dim j As Integer
onaji = 0
j = 1
While onaji = 0 And j < n
If a(j) = a(n) Then
onaji = 1
Else
j = j + 1
End If
Wend
End Function
   6月24日(木) 16:56:32     23146

過去問題一覧へ戻る