diff --git a/physics/einstein_mass_energy_equivalence_module.py b/physics/einstein_mass_energy_equivalence_module.py new file mode 100644 index 000000000000..ce06124bb2d3 --- /dev/null +++ b/physics/einstein_mass_energy_equivalence_module.py @@ -0,0 +1,32 @@ +# Einstein's Energy-Mass Equivalence #9191 (https://github.com/TheAlgorithms/Python/issues/9191) + +# https://www.github.com/JehanPatel + +# What is Einstein's Energy-Mass Equivalence +# It expresses the fact that mass and energy are the same physical entity and can be changed into each other. +# Refer https://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence for more information on the topic. + +# Module for Einstein's Energy-Mass Equivalence. + + +def calculate_energy_equivalent(mass): + """ + Calculate the energy equivalent of a given mass. + + :param mass: Mass in kilograms + :type mass: float + :return: Energy equivalent in joules + :rtype: float + """ + # Constants + G = 6.67430e-11 # Gravitational constant + c = 3.0e8 # Speed of light + h = 6.62607004e-34 # Planck constant + + # Calculate energy equivalent + energy_equivalent = mass * c**2 + + return energy_equivalent + + +# Happy Coding! diff --git a/project_euler/problem_095/project_euler_095.py b/project_euler/problem_095/project_euler_095.py new file mode 100644 index 000000000000..42527a026d69 --- /dev/null +++ b/project_euler/problem_095/project_euler_095.py @@ -0,0 +1,46 @@ +# Project Euler - Problem 95 +# Amicable Chains + +# https://www.github.com/JehanPatel + +# Refer to https://github.com/TheAlgorithms/Python/issues/9166 for further discussion on Project Euler - Problem 95 + +# What is Amicable Chains? +# Amicable chains are a sequence of numbers in which each number is the sum of the proper divisors of the number that follows it. For example, consider the sequence 220, 284, 220, 284, ... Here, 220 is the sum of the proper divisors of 284, and 284 is the sum of the proper divisors of 220. + +# Problem Statement - https://user-images.githubusercontent.com/118645569/271806807-863546a0-c723-437a-9475-3017e3218d55.png + +import itertools + + +def compute(): + LIMIT = 1000000 + + divisorsum = [0] * (LIMIT + 1) + for i in range(1, LIMIT + 1): + for j in range(i * 2, LIMIT + 1, i): + divisorsum[j] += i + + maxchainlen = 0 + ans = -1 + for i in range(LIMIT + 1): + visited = set() + cur = i + for count in itertools.count(1): + visited.add(cur) + next = divisorsum[cur] + if next == i: + if count > maxchainlen: + ans = i + maxchainlen = count + break + elif next > LIMIT or next in visited: + break + else: + cur = next + + return str(ans) + + +if __name__ == "__main__": + print(compute())