Digits of Pi

TarifEzaz PIHACKS'21-CodeJam
Limits 1s, 512 MB

Let’s talk about one fascinating fact about circles. For that, let’s perform the following experiment:

  1. Take any circle, it can be big or small.

  2. Measure it’s circumference. Denote the length of the circumference by C.

  3. Measure the diameter of the circle. Denote the length of the diameter by D.

  4. Measure C/D by calculating the result after dividing C with D.

If you perform the above three steps with different circles, you will always end up finding the exact same value in step 4. The constant found at step 4 is called Pi. The number of digits increases infinitely after the decimal point. But for many practical uses, we only take digits up to certain places after the decimal point. For example, the approximate value up to five decimal places for Pi would be 3.14159.

In this problem, you will be given a number x, you will have to print the sum of the digits of Pi up to x decimal places.


In this problem, you will be given a number xx, you will have to print the sum of the digits of Pi up to xx decimal places.

The first line of input will have TT ( 1<=T<=151 <= T <= 15 ), the number of test cases.

In each of the next TT lines, there will be an integer xx ( 0<=x<=150 <= x <= 15 ), the sum of digits after the decimal places up to which you will have to print as a result.

There is no sub-task for this problem, you will have to solve each cases completely to get the full points.


For each input xx, print an integer on a line, the intended sum.



The following code can be used to print some of the digits of Pi:

#include <bits/stdc++.h>

using namespace std ;

int main() {

double pi = 2 * acos(0.0);

cout << pi << endl ;

return 0 ;



Login to submit.


90% Solution Ratio
silenced.VOICEEarliest, Jul '21
Yasir_ArafatFastest, 0.0s
Mr.HmianLightest, 131 kB
silenced.VOICEShortest, 120B
Toph uses cookies. By continuing you agree to our Cookie Policy.