Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are performing a science experiment in a research laboratory. You are attempting to form a new compound. A compound is made up of
You are performing a science experiment in a research laboratory. You are attempting to form a new compound. A compound is made up of molecules and the mass of the compound is the sum of the masses of the molecules that compose the compound. For this experiment, you have identified four types of molecules: A, B, C and D. From these four molecules, A and B are monatomic, but C and D are diatomic. A monoatomic molecule is made up of one atom, but a diatomic molecule is made up of two atoms. So the mass of a diatomic molecule is twice its atomic mass while the mass of a monoatomic molecule is equal to its atomic mass. You have to form a compound X of mass Q using the maximum number of molecules. Write an algorithm to find the maximum number of molecules that can be used to form compound X. Input The first line of the input consists of an integer - atomicMassA, representing the atomic mass of atom A. The second line consists of an integer - atomicMassB, representing the atomic mass of atom B. The third line consists of an integer - atomicMassC, representing the atomic mass of atom C. The fourth line consists of an integer - atomicMassD, representing the atomic mass of atom D. The last line consists of an integer - atomicMassX, representing the atomic mass of compound X. Output Print an integer representing the maximum number of molecules that can be used to form compound X. Constraints 1 atomicMassA, atomicMassB, atomicMassC, atomicMassD 105 1 atomicMassX 107 Note You have an unlimited supply of the molecules. Molecules cannot be broken down into smaller units. Example Input: 5 8 5 3 23 Output: 4 Explanation: Molecular mass of a A-molecule(monoatomic) = 5 Molecular mass of a B-molecule(monoatomic) = 8 Molecular mass of a C-molecule(diatomic) = 10(5*2) Molecular mass of a D-molecule(diatomic) = 6(3*2) The best optimal fusion is to use three D molecules (6*3) and one A molecule (51) to create X of mass 23 (18+5). Hence, the total number of molecules used are 4. (a
Step by Step Solution
★★★★★
3.45 Rating (161 Votes )
There are 3 Steps involved in it
Step: 1
Here is the algorithm 1 Read the input atomic masses of A B C D and total mass of compound ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started