0
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コード(日記)

Posted at

# プログラム名: math_operations_all_in_one.py
# 内容: 素因数分解・累乗・演算・恒等式検証などを一括実行するPythonコード

import sympy as sp

# === (1) 1〜300 の素因数分解 ===
print("[1] 素因数分解 (1〜300)")
for n in range(1, 301):
    print(f"{n}: {sp.factorint(n)}")
print("-" * 50)

# === (2) 累乗と逆数の計算 ===
N = 10
print("[2] 累乗と逆数(N=10)")
print(f"2^{N} = {2**N}")
print(f"3^{N} = {3**N}")
print(f"5^{N} = {5**N}")
print(f"6^{N} = {6**N}")
print(f"7^{N} = {7**N}")
print(f"N×N = {N * N}")
print(f"1 / 2^{N} = {1 / 2**N:.10f}")
print(f"1 / 5^{N} = {1 / 5**N:.10f}")
print("-" * 50)

# === (3) 四則演算(A, B, C, D の設定) ===
A = 1000
B = 5
C = 999
D = 6

print("[3] 演算処理")
print(f"A - 1 = {A - 1}")
print(f"B + 1 = {B + 1}")
print(f"(C + 1) + (D - 1) = {(C + 1) + (D - 1)}")
print("-" * 50)

# === (4) A² = (A+B)(A−B) + B² の恒等式確認 ===
lhs = A**2
rhs = (A + B) * (A - B) + B**2
print("[4] 等式 A² = (A+B)(A−B) + B² の検証")
print(f"LHS = {lhs}")
print(f"RHS = {rhs}")
print("等式成立 ✅" if lhs == rhs else "等式不成立 ❌")
print("-" * 50)

# === (5) 演算:乗除 ===
print("[5] その他の演算")
print(f"48 × (100 − 1) = {48 * (100 - 1)}")
print(f"48 × (10 + 1) = {48 * (10 + 1)}")
print(f"133 ÷ 171 = {133 / 171:.10f}")
print("-" * 50)

0
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
0
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?