Previously we discussed the Equal Temperament Tuning System, which is by far the most common tuning system currently in use. But what other alternatives are there? The system of Pythagorean Tuning has been in use since ancient times, and is said to sound much "rounder" and "more resonant" than its Equal-Tempered counterpart.
Pythagorean tuning is based around the frequency ratio of 3/2 - specifically this is the ratio between some root note and its Perfect Fifth.
And so given some root note with frequency R, the Perfect Fifth is R * (3 / 2). For example given the root C4, then G4 exists a P5 above it.
But we can realize that D5 exists P5 above G4, and likewise A5 exists P5 above D5. In fact, we can stack our 3/2 calculations and then
adjust for octave.
However, let's also realize that we can move in the other direction, downwards. Again for a root of C4, then F3 exists P5 below C4, Bb
exists P5 below that, and so forth. By calculating the frequencies of stacked P5 intervals using 3/2 ratios and then adjusting for octave, we
can form a general equation of F = R * ((3 / 2) ^ n) * (2 ^ m), where n fifths are stacked and m octaves are adjusted.
Below is a table of ratios used. Notice that although many combinations of n and m may exist for any given note, the minimal absolute value of
n is chosen for each case.
| Interval | n | m | Pythagorean Tuning Frequency (Hz) |
Equal Temperament Frequency (Hz) |
|---|---|---|---|---|
| P1 | 0 | 0 | 261.626 | 261.626 |
| m2 | -5 | 3 | 275.622 | 277.183 |
| M2 | 2 | -1 | 294.329 | 293.665 |
| m3 | -3 | 2 | 310.075 | 311.127 |
| M3 | 4 | -2 | 331.120 | 329.628 |
| P4 | -1 | 1 | 348.834 | 349.228 |
| P5 | 1 | 0 | 392.438 | 391.996 |
| m6 | -4 | 3 | 413.433 | 415.305 |
| M6 | 3 | -1 | 441.493 | 440.000 |
| m7 | -2 | 2 | 465.112 | 466.164 |
| M7 | 5 | -2 | 496.680 | 493.883 |
| P8 | 0 | 1 | 523.251 | 523.251 |
You may have noticed the lack of TT Tritone interval. That specific interval is difficult to calculate in this tuning system,
being either understood as a raised "augmented" P4 interval or as a lowered "diminished" P5 interval. Let's ignore this case
for the scope of this problem.
To prevent you from just copying existing values, we will choose some Note Name as our root and assign it some random frequency. You will then be given further note names and will be expected to return the frequency of the next-highest note bearing that name, according to a Pythagorean Tuning.
Input Data
The first line will consist of two values - the note name of the root note, and its frequency in Hz.
The second line will consist of Q, the quantity of testcases.
Q lines will then follow, each holding one note name.
Answer
Should be Q space-separated values, corresponding to the freqencies of the given notes aocording to a Pythagorean Tuning.
Error should be less than 1e-3.
Example
input data:
D 345.678
3
A
D
C#
answer:
518.517 691.356 656.248