The output is output = sin(flag % pi()).
We can get flag % pi() = arcsin(output) using a binary search. Note that there are 2 possible answers.
So, we want to calculate k such that flag - k * pi() = arcsin(output).
Due to the Decimal, these values are calculated in 300-digits precision. That means,