回答編集履歴
1
説明不足
test
CHANGED
@@ -3,3 +3,107 @@
|
|
3
3
|
なんとなく再帰処理っぽい気はするのですが……。
|
4
4
|
|
5
5
|
![イメージ説明](1cbad9615bfa53791d8a28a96a80a9f0.png)
|
6
|
+
|
7
|
+
【追記】
|
8
|
+
|
9
|
+
表は[4,0,1,5]とかを、4015(7進数)などに見立てて数を調べた結果です。
|
10
|
+
|
11
|
+
プログラムは以下。
|
12
|
+
|
13
|
+
```VBA
|
14
|
+
|
15
|
+
'注意:下手にketaとかsinsuに大きな数字(10以上とか)を入れると、あっという間に固まります。
|
16
|
+
|
17
|
+
Sub Macro1()
|
18
|
+
|
19
|
+
Dim keta As Double
|
20
|
+
|
21
|
+
Dim sinsu As Double
|
22
|
+
|
23
|
+
Dim ans As Double
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
Dim i As Double
|
28
|
+
|
29
|
+
Dim mstr_i As String
|
30
|
+
|
31
|
+
Dim tmpsinsu As Double
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
keta = 3
|
36
|
+
|
37
|
+
sinsu = 4
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
ans = 0
|
42
|
+
|
43
|
+
i = 0
|
44
|
+
|
45
|
+
While i < sinsu ^ keta
|
46
|
+
|
47
|
+
mstr_i = S10_2(i, sinsu)
|
48
|
+
|
49
|
+
tmpsinsu = 0
|
50
|
+
|
51
|
+
mstr_i = Replace(mstr_i, "0", "") '先に0を抜いとく
|
52
|
+
|
53
|
+
While Len(mstr_i) Mod 2 = 0 And Len(mstr_i) <> 0
|
54
|
+
|
55
|
+
mstr_i = Replace(mstr_i, CStr(tmpsinsu), "")
|
56
|
+
|
57
|
+
tmpsinsu = tmpsinsu + 1
|
58
|
+
|
59
|
+
Wend
|
60
|
+
|
61
|
+
If Len(mstr_i) = 0 Then
|
62
|
+
|
63
|
+
ans = ans + 1
|
64
|
+
|
65
|
+
End If
|
66
|
+
|
67
|
+
i = i + 1
|
68
|
+
|
69
|
+
Wend
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
MsgBox "sinsu=" & sinsu & " keta=" & keta & " ans=" & ans
|
74
|
+
|
75
|
+
End Sub
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
'10進→2進
|
80
|
+
|
81
|
+
Function S10_2(X As Double, sin As Double) As String
|
82
|
+
|
83
|
+
Dim XX As Double
|
84
|
+
|
85
|
+
Dim Y As String
|
86
|
+
|
87
|
+
XX = X
|
88
|
+
|
89
|
+
If (XX < 0) Then
|
90
|
+
|
91
|
+
Y = "Error"
|
92
|
+
|
93
|
+
Else
|
94
|
+
|
95
|
+
Do
|
96
|
+
|
97
|
+
Y = XX Mod sin & Y
|
98
|
+
|
99
|
+
XX = XX \ sin
|
100
|
+
|
101
|
+
Loop While (XX > 0)
|
102
|
+
|
103
|
+
End If
|
104
|
+
|
105
|
+
S10_2 = Y
|
106
|
+
|
107
|
+
End Function
|
108
|
+
|
109
|
+
```
|