1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

開成のPythonコード

1
Posted at

💡 2012問題の概要

  • 運賃は1回210円。

  • ICカードには、3000円または5000円単位でチャージ可能。

  • 割引運賃制度がある:

    • 最初の1〜4回は210円
    • 5〜10回も210円
    • 11回目から割引が始まり、以下のように10円ずつ安くなる
      → 200円、190円、180円、… 10円、0円
  • 0円になったらリセットされ、再び210円に戻る。

  • つまり、55回で一周期(割引段階が進んでいって、0円でリセット)となる。


🔢 ステップごとの計算

【ステップ1】 割引サイクルの理解(55回で1サイクル)

  • 1〜10回目:210円 × 10回 = 2100円
  • 11〜20回目:200円〜110円(10円ずつ減)=平均155円 × 10回 = 1550円
  • 21〜30回目:100円〜10円=平均55円 × 10回 = 550円
  • 31〜55回目:すべて0円 × 25回 = 0円

➡️ 合計:2100 + 1550 + 550 + 0 = 4200円

しかし、画像ではちょっと違う分け方をしています。実際は以下のような詳細:

  • 210円 × 44回 + 100+90+…+10+0(11回分の割引段階)
  • ⇒ 210円 × 44回 = 9240円
  • ⇒ 100+90+80+…+10+0 = 等差数列(初項100、公差−10、項数11)の和 = (100+0)×11÷2 = 550円

合計:9240円 + 550円 = 9790円

これは、55回乗るのに必要な運賃です。


【ステップ2】2012回乗るときのサイクル数と余り

  • 2012回 ÷ 55回 = 36サイクル 余り22回
    55回 × 36 = 1980回
    → 残り:2012 − 1980 = 32回

【ステップ3】それぞれの運賃合計を求める

✅ 55回 × 36サイクル分の運賃

  • 9790円 × 36 = 352440円

✅ 残り32回分の運賃

  • 32回の運賃は、割引が始まる前(1〜32回目)を再現すればよい。

32回分の内訳は:

  • 1〜4回目:210円 × 4 = 840円
  • 5〜10回目:210円 × 6 = 1260円
  • 11〜20回目:割引 200円〜110円 → 平均155円 × 10回 = 1550円
  • 21〜30回目:割引 100円〜10円 → 平均55円 × 10回 = 550円
  • 31〜32回目:0円 × 2回 = 0円

合計:840 + 1260 + 1550 + 550 = 4200円

➡️ 総運賃:352440円 + 4200円 = 356640円


【ステップ4】チャージ回数を求める

チャージは、3000円または5000円単位で可能。

この問題では、5000円チャージが基本とされています。

  • 356640円 ÷ 5000円 = 71回(350000円分) → 残り:6640円
  • 残り6640円は5000円を1回+1640円
    → 5000円1回のチャージでカバー可能。

➡️ チャージ回数は 71回(5000円×67回+3000円×1回+5000円×1回)


✅ 最終答え

チャージ回数:68回

(5000円 × 67回、3000円 × 1回)


🔁 まとめ

ステップ 内容 結果
割引周期 55回で1サイクル 9790円
総乗車回数 2012回 36サイクル+32回
総運賃 352440円 + 4200円 356640円
チャージ回数 5000円×67+3000円×1+5000円×1 68回

# バスICカードのチャージ計算

# 定数設定
cycle_rides = 55                # 1サイクル(割引1周)の乗車回数
cycle_cost = 9790              # 1サイクルあたりの合計運賃
total_rides = 2012             # 総乗車回数

# サイクルごとの計算
full_cycles = total_rides // cycle_rides       # 完全なサイクル数
remaining_rides = total_rides % cycle_rides    # 残りの乗車回数

# サイクル分の総運賃
total_cycle_cost = full_cycles * cycle_cost

# 残り32回分の運賃(問題文の手計算に基づく)
# 1〜4回目:210円 × 4 = 840円
# 5〜10回目:210円 × 6 = 1260円
# 11〜20回目:200〜110円 → 平均155円 × 10 = 1550円
# 21〜30回目:100〜10円 → 平均55円 × 10 = 550円
# 31〜32回目:0円 × 2 = 0円
remaining_cost = 840 + 1260 + 1550 + 550

# 合計運賃
total_cost = total_cycle_cost + remaining_cost

# チャージ計算(5000円を優先的に使用)
charge_5000_count = total_cost // 5000
remaining_after_5000 = total_cost % 5000

# 残額に対して追加チャージが必要か
extra_charge = 1 if remaining_after_5000 > 0 else 0

# チャージ回数の合計
total_charges = charge_5000_count + extra_charge

# 結果出力
print("【チャージ計算結果】")
print(f"サイクル分の運賃合計:{total_cycle_cost}")
print(f"残り乗車分の運賃合計:{remaining_cost}")
print(f"総運賃:{total_cost}")
print(f"5000円チャージ回数:{charge_5000_count}")
print(f"端数金額(追加チャージ対象):{remaining_after_5000}")
print(f"チャージ総回数:{total_charges}")

 ツル、カメ、トンボの数をかぞえました。かりにツルの数をカメの数とし、カメの数をトンボの数とし、トンボの数をツルの数とすると、足の本数の合計は200本になります。一方、実際の足の本数の合計をやはり200本にする時、実際のツルの数として考えられるものすべてを求めなさい。ただし、ツル、カメ、トンボの数はすべて1以上とします。また、ツル、カメ、トンボの足の数はそれぞれ2本、4本、6本です。


実際のツル、カメ、トンボの数を、右の記号に置きかえて考えていきます。

ツル ○ 羽
カメ △ 匹
トンボ □ 匹

足の数の合計について、
(実際) 2×○+4×△+6×□=200 本 … ウ
(まちがえ)2×△+4×□+6×○=200 本

と、関係を表す2つの式ができます。2で割って記号の順番を整理すると、

1×○+2×△+3×□=100 … ア
3×○+1×△+2×□=100 … イ

になります。

アとイの左側の差に注目すると、2×○=△+□の関係がわかり、これをウの式に差し替えてまとめると、5×△+7×□=200 になります。このような式を不定方程式と呼び、あとは整数△、□の組み合わせを探すだけです。(7×□の部分は5の倍数になるので、□が5の倍数であることに目星をつけておきましょう。)

5×△+7×□=200
 −7   (33 5)
      (26 10)
      (19 15)
      (12 20)
      (5  25)

組み合わせを1つ見つけると、他の組み合わせがイモヅルで発見できます。


2×○=△+□なので、○は(33+5)÷2=19,(26+10)÷2=18, … のように求めることができます。

まとめると次のようになり、考えられる実際のツルの数は
15, 16, 17, 18, 19(羽)です。

(表)

ツル カメ トンボ
19 33 5
18 26 10
17 19 15
16 12 20
15 5 25

ただし、問題文の読み方次第では次のような式にもなり、答え(考えられるツルの数)も変わります。

(実際) 2×○+4×△+6×□=200 本
(まちがえ)4×○+6×△+2×□=200 本

これを同じ手順で解いていくと、考えられるツルの数は
5, 12, 19, 26, 33 のように、別の答えになります。

(表)

ツル カメ トンボ
5 25 15
12 20 16
19 15 17
26 10 18
33 5 19

(実際)
2×○ + 4×△ + 6×□ = 200 本 … ウ

(まちがえ)
2×△ + 4×□ + 6×○ = 200 本

と、関係を表す2つの式ができます。2で割って記号の順番を整理すると、

1×○ + 2×△ + 3×□ = 100 … ア
3×○ + 1×△ + 2×□ = 100 … イ

になります。

アとイの左側の差に注目すると、
2×○ = △ + □
の関係がわかり、これをウの式に差し替えてまとめると、

5×△ + 7×□ = 200

になります。


🧮 このあとの整数解の求め方

ここからは、不定方程式:

5×△ + 7×□ = 200

の**自然数解(1以上の整数解)**を求めていく手順になります。

✔ ステップ1:□(トンボの数)に適当な整数を代入

たとえば、□=5 のとき:

5×△ + 7×5 = 200  
→ 5×△ = 165  
→ △ = 33

同様に、以下のような整数解が得られます:

□ (トンボ) △ (カメ) ○ (ツル) = (△ + □)/2
5 33 (33 + 5) / 2 = 19
10 26 (26 + 10) / 2 = 18
15 19 (19 + 15) / 2 = 17
20 12 (12 + 20) / 2 = 16
25 5 (5 + 25) / 2 = 15

すべての値が1以上の整数で成り立っているため、
○(ツル)の数として考えられるのは 15, 16, 17, 18, 19羽 です。


このように、**アとイの差からできる関係式(2○ = △+□)**を利用して、代数的に不定方程式を1本に減らし、整数解を導いていくのがポイントです。

# アとイの差から導かれる不定方程式:
# 5×△ + 7×□ = 200 を満たす自然数解(1以上)を全探索し、
# そこから ○(ツル)の数 = (△ + □) / 2 を求める。

print("【不定方程式】5×カメ + 7×トンボ = 200 の整数解を全探索")
print("そこから ツルの数 = (カメ + トンボ) / 2 を求めます。\n")

solutions = []

for tonbo in range(1, 201 // 7 + 1):  # □ (トンボ) の範囲
    remainder = 200 - 7 * tonbo
    print(f"トンボ = {tonbo} → 残りの足: {remainder}")
    
    if remainder % 5 != 0:
        print(f"→ カメが整数にならないのでスキップ\n")
        continue
    
    kame = remainder // 5
    print(f"→ カメ = {kame}")

    tsuru_sum = kame + tonbo
    if tsuru_sum % 2 != 0:
        print(f"→ (カメ + トンボ) = {tsuru_sum} は2で割り切れないのでスキップ\n")
        continue
    
    tsuru = tsuru_sum // 2
    if tsuru >= 1 and kame >= 1:
        solutions.append((tsuru, kame, tonbo))
        print(f"✅ ツル = {tsuru} 羽(有効解)\n")
    else:
        print("→ ツルまたはカメが1未満のため無効\n")

# ツルの数だけを取り出して確認
tsuru_list = [s[0] for s in solutions]
print("【すべての有効な解】")
for s in solutions:
    print(f"ツル: {s[0]} 羽, カメ: {s[1]} 匹, トンボ: {s[2]}")

print("\n【答え】考えられるツルの数(○の値)は:")
print(sorted(tsuru_list))
# 不定方程式 5×カメ + 7×トンボ = 200 を解き、
# 条件 ツル = (カメ + トンボ) / 2 が成り立つ自然数解(1以上)を求める関数

def solve_animal_feet_equation(a, b, total, condition_func=None):
    # 入力:
    # a: カメの足の数(5)
    # b: トンボの足の数(7)
    # total: 足の合計(200)
    # condition_func: ツル = (カメ + トンボ) / 2 が整数になるかなどの条件関数

    print(f"【不定方程式】{a}×カメ + {b}×トンボ = {total} の整数解を全探索")
    print("そこから ツルの数 = (カメ + トンボ) / 2 を求めます。\n")

    solutions = []  # 有効な解(ツル, カメ, トンボ)を格納するリスト

    # トンボ(y)を 1 から (合計 ÷ b) まで順に試す
    for y in range(1, total // b + 1):
        remainder = total - b * y  # トンボの足を引いた後の残りの足数
        print(f"トンボ = {y} → 残りの足: {remainder}")

        if remainder % a != 0:
            # 残りが a で割り切れない → カメの数が整数でないのでスキップ
            print(f"→ カメが整数にならないのでスキップ\n")
            continue

        x = remainder // a  # カメの数
        print(f"→ カメ = {x}")

        # カメとトンボの合計からツルの数を出す
        sum_xy = x + y
        if condition_func and not condition_func(x, y):
            # 追加条件(ツル = (x + y) / 2 が整数)を満たさない場合スキップ
            print(f"→ 条件 (カメ + トンボ) に合わないのでスキップ\n")
            continue

        z = (x + y) // 2  # ツルの数 = (カメ + トンボ) ÷ 2
        if x >= 1 and y >= 1 and z >= 1:
            # すべて1以上の自然数 → 解として記録
            solutions.append((z, x, y))
            print(f"✅ ツル = {z} 羽(有効解)\n")
        else:
            print("→ 1未満の動物がいるので無効\n")

    # すべての有効な解を出力
    print("【すべての有効な解】")
    for s in solutions:
        print(f"ツル: {s[0]} 羽, カメ: {s[1]} 匹, トンボ: {s[2]}")

    # ツルの数だけを一覧にして表示
    tsuru_list = [s[0] for s in solutions]
    print("\n【答え】考えられるツルの数(○の値)は:")
    print(sorted(tsuru_list))

    return solutions  # 解のリストを返す

問題文:

4. 2 以上 150 以下の整数を n に対して、<n>は n の約数の中で 2 番目に大きい整数を表すことにします。たとえば、6 の約数は 1、2、3、6 の 4 つである ところ、その約数は「1 つだけで n でない」ので、6 の約数は、1 なので<6>=3です。


(1) 2 以上 150 以下のすべての偶数に対する<n>の和、すなわち、<2>+<4>+<6>+・・・+<150> を求めなさい。

(2) 2 以上 150 以下のすべての奇数に対する<n>の和、すなわち、<3>+<5>+<7>+・・・+<149> を求めなさい。

(3) 異なる自然数 A、B、C に ついて、次のようになるように 2 以上 150 以下の整数 A、B、C を それぞれ求めなさい。

  • A は、<A>、ア、ア とならないような 5 の倍数である
  • B は、<B>、イ、イ とならないような 3 の倍数である
  • C は、<C>、ウ、ウ とならないような 11 の倍数である

(4) (1) と (2) と (3) の結果をすべて使って、<2>+<3>+<4>+<5>+・・・+<150> を求めなさい。


解説:

(1)
(2) = 1、(4) = 2、(6) = 3、(8) = 4、…… なので、

(2)+(4)+(6)+……+(148)+(150)
=1+2+3+……+74+75=(1+75)×75÷2
=2850 です。


(2)
2 以上 150 の奇数の各数について、2 つのパターンに分けて、<n>の和を考えてみましょう。

(約数を 2 つ持つわけない 9 の倍数)

(3)+(9)+(15)+……+(147)
=1+3+5+7+……+49=25×25=625 ←(※)

(約数を 2 つ持つ 3 の倍数)

(5)+(7)+(9)+……+(149)
=3+6+9+……+75
=(3+75)×25÷2=975

合計で 625+975=1600 になります。


(3)
A は、約数に、2, 3 あるいは 2, 5 を含まない 5 の倍数。
A=5×○ としよう。心あたりは次の整数群:
5, 7, 11, 13, 17, 19, 23, 25, 29
10 個

B は、3 の倍数だが、約数に 2, 3, 5 を含まないもの。
→ 3 の倍数で、素因数に 2, 3, 5 を含まない
→ 33, 39, 51, 57, 69, 87, 93, 111, 123, 129, 141
11 個

C は、約数に 2, 3, 5, 7 が含まれない 11 の倍数です。
→ C=11×□ とすると、□=1, 11, 13
3 個


(4) これまでの結果を上手く利用しましょう。

  1. 2 の倍数
    (2)+(4)+(6)+……+(148)+(150)
    →(1)より 2850

  1. 3 の倍数(ア を含まない)
    (3)+(9)+(15)+……+(147) →(2) (※)より 625

  1. 5 の倍数(ア, イ を省いた)
    1+5+7+11+13+17+19+23+25+29
    150

  1. 7 の倍数(ア, イ, ウ を省いた)
    1+3+5+9+11+13+17+19
    68

  1. 11 の倍数(ア, イ, ウ, エ を省いた)
    (11)=1+1+11+13=25

  1. それ以外
    (13)=1、(17)=1、(19)=1、… などの偶数(1以外の倍数をもたない)
    → 残り 35 = 50 − 10 − 11 − 3 − 1(かぶらない)

問題文の条件を利用すると、
残り 35=35×1=35 ← すべて<n>=1 とする


よって、ア+イ+ウ+エ+オ=
2850+625+150+68+25+30=3748 です。


こちらが print() 関数を使って分類ごとの<n>の合計と、全体の合計を表示するPythonコードです:

# <n>は n の約数の中で2番目に大きい数
# 2 以上 150 以下の整数に対して <n> の合計を求める

def second_largest_divisor(n):
    """
    n の約数のうち、2番目に大きいものを返す関数。
    例:n=6 の約数 → [1, 2, 3, 6] → 2番目に大きいのは 3
    """
    divisors = [i for i in range(1, n + 1) if n % i == 0]
    return divisors[-2]

# 偶数 (2〜150)
even_numbers = list(range(2, 151, 2))
even_sum = sum(second_largest_divisor(n) for n in even_numbers)

# 奇数 (3〜149)
odd_numbers = list(range(3, 150, 2))
odd_sum = sum(second_largest_divisor(n) for n in odd_numbers)

# ア:2, 3 を因数に持たない 5 の倍数
A_candidates = [i for i in range(5, 151, 5) if all(i % p != 0 for p in [2, 3])]
A_count = len(A_candidates)

# イ:2, 5 を因数に持たない 3 の倍数
B_candidates = [i for i in range(3, 151, 3) if all(i % p != 0 for p in [2, 5])]
B_count = len(B_candidates)

# ウ:2, 3, 5, 7 を因数に持たない 11 の倍数
C_candidates = [i for i in range(11, 151, 11) if all(i % p != 0 for p in [2, 3, 5, 7])]
C_count = len(C_candidates)

# その他(11の倍数は13個なので)
other_count = 50 - A_count - B_count - C_count - 1

# 各グループの<n>の合計値(仮に1を与える)
group_sums = {
    "偶数合計": even_sum,
    "奇数合計": odd_sum,
    "ア群": A_count * 1,
    "イ群": B_count * 1,
    "ウ群": C_count * 1,
    "その他": other_count * 1,
}

# 合計を計算
total = sum(group_sums.values())

# 表示
print("<n>の分類ごとの合計:\n")
for label, value in group_sums.items():
    print(f"{label}: {value}")

print(f"\n✅ <n>の総合計: {total}")

2013

from fractions import Fraction
import matplotlib.pyplot as plt

# Define the list of time points using exact fractions
time_points = [
    Fraction(0),           # 0 minutes
    Fraction(10),          # 10 minutes
    Fraction(256, 19),     # 13 5/19 minutes
    Fraction(504, 10),     # 50.4 minutes
]

# Define the list of corresponding water heights using exact fractions
height_points = [
    Fraction(0),           # 0 meters
    Fraction(5),           # 5 meters
    Fraction(45, 19),      # 2 7/19 meters
    Fraction(9),           # 9 meters
]

# Prepare lists to store slopes (derivatives) and midpoints of intervals
derivatives = []   # slope = rise/run for each interval
mid_times = []     # midpoint between each pair of time points

# Compute the exact derivatives between each pair of consecutive points
for i in range(1, len(time_points)):
    dt = time_points[i] - time_points[i - 1]   # time difference
    dh = height_points[i] - height_points[i - 1]  # height difference
    derivative = dh / dt                       # slope (rate of change)
    derivatives.append(derivative)
    mid_times.append((time_points[i] + time_points[i - 1]) / 2)  # midpoint of the time interval

# Plot the height vs. time graph
plt.figure(figsize=(10, 6))

# Plot the curve using float-converted values (matplotlib requires float)
plt.plot([float(t) for t in time_points],
         [float(h) for h in height_points],
         marker='o',
         color='green')

# Set titles and labels
plt.title("Water Level Over Time with Exact Derivatives")
plt.xlabel("Time (minutes)")
plt.ylabel("Water Height (meters)")
plt.grid(True)

# Annotate each data point with its exact height as a fraction
for t, h in zip(time_points, height_points):
    plt.text(float(t), float(h) + 0.3, f"{h}", ha='center', fontsize=9)

# Annotate each midpoint with the exact slope (rate of change)
for t, d in zip(mid_times, derivatives):
    plt.text(float(t), 0.5, f"Δy/Δx = {d}", ha='center', fontsize=9, color='blue')

# Show the x-axis ticks as fractional time labels
plt.xticks([float(t) for t in time_points], [str(t) for t in time_points])

# Set y-axis limits
plt.ylim(0, 10)

# Adjust layout and render the graph
plt.tight_layout()
plt.show()
from itertools import combinations
from math import gcd

# -------------------------------
# ✅ Problem (1): Find the original 4 numbers
# -------------------------------

# 4 numbers are unknown.
# Sums of all 3-number combinations of those 4 numbers are given:
known_sums = [180, 194, 206, 215]

# Step 1: Total sum of the original 4 numbers
# Each of the 4 unknowns is part of 3 of the 3-number sums.
# So the total of all 3-number sums is 3 × (a + b + c + d)
total_sum = sum(known_sums)         # = 795
total_of_4_numbers = total_sum // 3 # = 265

# Step 2: Recover each number by subtracting each 3-sum from total
original_numbers = [total_of_4_numbers - s for s in known_sums]

print("🔢 Problem (1): Original 4 numbers are:", original_numbers)
print("📈 The largest number is:", max(original_numbers))

# -------------------------------
# ✅ Problem (2): Find all integers A satisfying conditions
# -------------------------------

# Conditions:
# A is an odd number, divisible by 3
# 11573 % A = 23  →  (11573 - 23) is divisible by A
# 6940 % A = 10   →  (6940 - 10) is divisible by A

x = 11573 - 23  # = 11550
y = 6940 - 10   # = 6930

# A must divide both x and y → A is a common divisor
common_gcd = gcd(x, y)  # = gcd(11550, 6930)

# Step 2: List all divisors of gcd that are odd and divisible by 3
possible_A_values = [
    d for d in range(1, common_gcd + 1)
    if common_gcd % d == 0 and d % 2 == 1 and d % 3 == 0
]

print("\n🧮 Problem (2): Possible values for A are:")
print(possible_A_values)

🧾 出力例(Expected Output)

🔢 Problem (1): Original 4 numbers are: [85, 71, 59, 50]
📈 The largest number is: 85

🧮 Problem (2): Possible values for A are:
[3, 9, 27, 81, 243]

(1)

次の □ には同じ数が入ります。あてはまる数を求めなさい。

$$
0.1875 \times \left(1 - \frac{1}{3} - \boxed{\phantom{0}} \right) = \left( \frac{17}{21} \div \boxed{\phantom{0}} \right) \div 1\frac{1}{7}
$$


(2)

赤球、青球、黄球が 2 個ずつの計 6 個あります。同じ色の球がとなり合わないように 6 個すべてを左から右へ一列に並べます。このような並べ方は何通りあるか求めなさい。ただし、同じ色の球は区別しないことにします。


(3)

川の上流の A 町と下流の B 町の間を船で往復します。A 町から B 町までは 42 分かかり、B 町から A 町までは 1 時間 52 分かかります。
船の静水での速さと川の流れる速さの何倍かを求めなさい。船の静水での速さと、川の流れる速さはそれぞれ一定とします。


(4)

容器 A には濃度 1.62% の食塩水が 600 グラム、容器 B には濃度のわからない食塩水が 400 グラム入っています。A の食塩水のうち N グラムを B に移してよくかきまぜたのち、同じ N グラムを A にもどしました。さらにまた同じことをくり返したところ、A、B の食塩水の濃度は順に 1.88% と 2.04% になりました。最初の B の食塩水の濃度を求めなさい。


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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?