LoginSignup
1
0

2024の約数「2024 慶応義塾大学 理工学部【1】(1)」をChatGPTとsympyでやってみたい。穴埋め (ア)(イ)のMathMLの対応。

Last updated at Posted at 2024-03-22

・穴埋め (ア)(イ)のMathMLの対応。

オリジナル

大学入試数学問題集成 様>【1】(1) テキスト

公式ホームページ
解答例の公表
https://www.keio.ac.jp/ja/admissions/news/files/2024/3/6/2024_st_math.pdf
https://www.keio.ac.jp/ja/admissions/ippan_kaitou/

google検索で

2024の約数と個数
「2024」という数の特徴
正の約数が全部で16個(1, 2, 4, 8, 11, 22, 23, 44, 46, 88, 92, 184, 253, 506, 1012, 2024)もある。2024/01/01

ChatGPT-3.5先生へ

・大学入試数学問題集成 様のMathMLを抜粋。Pから/Pまで。

<p class="s1level"><a name="q-0301" 
id="q-0301"></a><span 
class="qnum">【1】</span><a 
name="s-0301" id="s-0301"></a><span 
class="shomon1">(1)</span> <math>

しょうりゃく

<mtext>(イ)</mtext><mspace width="1em"></mspace></mrow><mspace width=".2em"></mspace>
</math>である.
</p>

回答しょうりゃく
ここで、(ア)と(イ)の部分は問題の解答を表しています。

sympyで

回答しょうりゃく

from sympy import divisors, Integer, root

# 2024の約数を見つける
divs = divisors(2024)

# アの値を計算する
a_value = sorted(divs)[5]  # 6番目の要素

# イの値を計算する
sixth_root = root(2024, 6)
closest_integer = Integer(sixth_root).round()

print("アの値:", a_value)
print("イの値:", closest_integer)

・SymPy Liveで

???

アの値: 22
イの値: 3

(私)ChatGPT先生の計算間違いです。

sympyで 最も近い自然数の関数

・ChatGPT-3.5先生に教えてもらったので、以下追加修正。

sympyで

from sympy import divisors, root, Integer
from sympy import *

def nearest_integer(x):
    """
    Return the nearest integer to the given number x.
    """
    return int(round(x))

# 使用例
# x = 3.7

# 2024の約数のリストを取得
divisor_list = list(divisors(2024))

# 6番目に大きい約数を取得
sixth_largest_divisor = divisor_list[-6]

# 2024の6乗根を計算
sixth_root_of_2024 = root(2024, 6)

# 最も近い自然数を取得
nearest_integer_to_sixth_root = Integer(sixth_root_of_2024)

# 結果を出力
print("2024の6番目に大きい約数は`   :", sixth_largest_divisor)
print("2024の6乗根に最も近い自然数は:", nearest_integer(sixth_root_of_2024))
# 2024の6番目に大きい約数は`   : 92
# 2024の6乗根に最も近い自然数は: 4

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0