(20220328)1次不定方程式?考察?を使っていません。
問題:第4問(選択問題)(配点20) <毎日新聞
整数の性質
(1) 5**4*x-2**4*y-1
(3) 5**5*x-2**5*y-1
(4)11**5*x-2**5*y-1
https://mainichi.jp/exam/kyotsu-2022
解答<毎日新聞#page=25
2022大学入学共通テスト本試数学IA【4】
テキスト文字が使えます。
考察を使ったvba
(勉強中)
考察を使っていないvba
1から順に,代入して計算しました。もっとかっこよくなるような気がします。
普通は、while文。以下は、適当に200?
Const nMax = 200
Sub aaa_main()
ActiveSheet.Cells.Clear
iR = 0
For i = 1 To nMax
y = (5 ^ 4 * i - 1) / 2 ^ 4
If y = Int(y) Then
iR = iR + 1
Cells(iR, 1) = i
Cells(iR, 2) = y
GoTo jmp1_1
End If
Next
jmp1_1:
For i = 10 To nMax
y = (5 ^ 4 * i - 1) / 2 ^ 4
If y = Int(y) Then
iR = iR + 1
Cells(iR, 1) = i
Cells(iR, 2) = y
GoTo jmp_3
End If
Next
jmp_3:
iR = iR + 1
Cells(iR, 1) = Log(625 ^ 2) / Log(5)
m = Cells(1, 2)
Cells(iR, 2) = Log((625 ^ 2 - 2 ^ Cells(3, 1) * (m ^ 2) - 1) / m) / Log(2)
For i = 100 To nMax
y = (5 ^ 5 * i - 1) / 2 ^ 5
If y = Int(y) Then
iR = iR + 1
Cells(iR, 1) = i
Cells(iR, 2) = y
GoTo jmp4
End If
Next
jmp4:
For i = 1 To nMax
y = (11 ^ 5 * i - 1) / 2 ^ 5
If y = Int(y) Then
iR = iR + 1
Cells(iR, 1) = i
Cells(iR, 2) = y
GoTo jmp5
End If
Next
jmp5:
Const myFormula1 = " 5^4*x-2^4*y-1"
Const myFormula2 = " 5^5*x-2^5*y-1"
Const myFormula3 = "11^5*x-2^5*y-1"
Cells(1, 3) = "ア,イウ 1, 39 3点 " & myFormula1
Cells(2, 3) = "エオ,カキク 17, 664 2点,2点" & myFormula1
Cells(3, 3) = "ケ,コ 8, 5 2点 "
Cells(4, 3) = "サシス,セソタチツ 125,12207 3点,3点" & myFormula2
Cells(5, 3) = "テト,ナニヌネノ 19,95624 3点,2点" & myFormula3
End Sub
1 39 ア,イウ 1, 39 3点 5^4*x-2^4*y-1
17 664 エオ,カキク 17, 664 2点,2点 5^4*x-2^4*y-1
8 5 ケ,コ 8, 5 2点
125 12207 サシス,セソタチツ 125,12207 3点,3点 5^5*x-2^5*y-1
19 95624 テト,ナニヌネノ 19,95624 3点,2点11^5*x-2^5*y-1
考察を使っていないvbaソルバー
答えがあっているのは、偶然かな。もっと短くなるような気がします。
Const myMethod = "GRG Nonlinear"
Const myFormula1 = " 5^4*x-2^4*y-1"
Const myFormula2 = " 5^5*x-2^5*y-1"
Const myFormula3 = "11^5*x-2^5*y-1"
Function xy2cell(f As String)
Dim g As String
g = f
g = Replace(g, "x", "RC[-2]")
g = Replace(g, "y", "RC[-1]")
xy2cell = "=" & g
End Function
Sub mySolver(iR, myFormula As String, myMin)
Cells(iR, 3).formula = xy2cell(myFormula)
Dim ws As Worksheet: Set ws = ActiveSheet
SolverReset
SolverOk setCell:=ws.Cells(iR, 3), _
MaxMinVal:=3, _
ByChange:=ws.Range(Cells(iR, 1), Cells(iR, 2)), _
EngineDesc:=myMethod
SolverAdd CellRef:=Range(Cells(iR, 1), Cells(iR, 2)).Address, Relation:=4
SolverAdd CellRef:=Cells(iR, 1).Address, Relation:=3, formulaText:=myMin
SolverOptions AssumeNonNeg:=False
SolverSolve UserFinish:=True
End Sub
Sub aaa_main()
ActiveSheet.Cells.Clear
iR = 1
Call mySolver(iR, myFormula1, 0)
iR = iR + 1
Call mySolver(iR, myFormula1, 10)
iR = iR + 1
Cells(3, 1) = Log(625 ^ 2) / Log(5)
m = Cells(1, 2)
Cells(3, 2) = Log((625 ^ 2 - 2 ^ Cells(3, 1) * (m ^ 2) - 1) / m) / Log(2)
iR = iR + 1
Call mySolver(iR, myFormula2, 100)
iR = iR + 1
Call mySolver(iR, myFormula3, 0)
'
Cells(1, 4) = "ア,イウ 1, 39 3点 " & myFormula1
Cells(2, 4) = "エオ,カキク 17, 664 2点,2点" & myFormula1
Cells(3, 4) = "ケ,コ 8, 5 2点 "
Cells(4, 4) = "サシス,セソタチツ 125,12207 3点,3点" & myFormula2
Cells(5, 4) = "テト,ナニヌネノ 19,95624 3点,2点" & myFormula3
End Sub
結果
1 39 0 ア,イウ 1, 39 3点 5^4*x-2^4*y-1
17 664 0 エオ,カキク 17, 664 2点,2点 5^4*x-2^4*y-1
8 5 0 ケ,コ 8, 5 2点
125 12207 0 サシス,セソタチツ 125,12207 3点,3点 5^5*x-2^5*y-1
19 95624 0 テト,ナニヌネノ 19,95624 3点,2点11^5*x-2^5*y-1
参考
設定が必要です。初期設定たど、エラーがでると思います。
k^5x-2^5y=1の整数解(2022年共テ数ⅠA第4問)< 理系のための備忘録