A visual representation of pressure waves being produced by a central oscillating source.
Many of us are familiar with a piano, with how keys on the left side produce lower pitches while the keys on the right produce higher pitches. But what causes tones to be higher or lower? All sound is caused by pressure waves in the air which your eardrum is able to pick up on. These pressure waves are similar to the ripples on the surface of a pond.
Imagine what a bug floating at some point on the surface of the pond would experience. If the ripples were closely spaced together then the water
would change back and forth very quickly, whereas if the ripples were spaced far apart then the water level would oscillate slower. The speed of
this oscillation is called Frequency, and is usually measured with the unit of
Hertz, frequently abbreviated as "Hz" and defined as 1 Hz = 1 / second.
And so if your ear perceives pressure waves with high Frequency then you hear a high-pitched tone, and vice versa.
But, that explanation hardly explains what is going on at a piano. Who decides which keys make which pitches, or how many keys there are on the paino? There are a few ways to answer that question, but the method of determining note pitches that is commonly used today is known as Equal Temperament.
To start, we need to know a few things:
2*X Hz will sound twice as "high" as a note with frequency X Hz. X and 2*X is known as an Octave.We should define what we mean by "equal sections" in this context. Because the distance between each octave is double the previous, we must plot our frequencies Logarithmically in base 2, rather than Linearly.
For example, let's imagine we wanted to split up the range between 220 Hz and 440 Hz into equal Logarithmic sections. If we wanted to cut it in
half, we would compute 220 * (2 ^ (1 / 2)) to find the "midpoint". If we wanted to cut it into thirds, we would use points at 220 * (2 ^ (1 / 3)) and
220 * (2 ^ (2 / 3)). And so to cut it into 12 logarithmic sections, we use points at 220 * (2 ^ (i / 12)).
Next, let's understand a little about how these frequencies are called - each one has a note name and an octave. The note names range across 7 letters
between A and G, although some have "sharp" notes in between which are marked by a # symbol. Listed out, the notes appearing between A4 and A5
are as follows: A4, A#4, B4, C5, C#5, D5, D#5, E5, F5, F#5, G5, G#5, A5. Note that the octave number increments at C, and also that there are no
B-sharp nor E-sharp listed.
Both note name and octave number are defined rather arbitrary as A4 = 440 Hz, and all other note frequencies being calculated from there. Even though
the exact values are arbitrary, universally agreeing on common values allows different instruments to be "in-tune" with each other. However, to prevent you from just copying the values from that link, we'll define our A4 to be a slightly different frequency.
At this point you may be asking yourself why all of this is how it is... Answers to these questions are planned for future problems, so for now let's focus on the problem at hand :)
Input Data
The first line will be A, our defintion of A4 for this problem, in Hz.
The second line will be Q, the quantity of testcases.
Q lines will then follow, each being a note in the format used above. For example, D#5.
Answer
Should consist of Q space-separated values, corresponding to the frequencies of the notes given.
Error should be less than 1e-3.
Example
input data:
523
4
A4
A#4
F2
G#8
answer:
523 554.099 103.776 7898.340