-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi.cpp
80 lines (63 loc) · 1.03 KB
/
pi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
using namespace std;
int A = 103993;
int B = 33102;
string str = "415926530119026040722614947737296840070086399613316";
void print_pi(long long int n ) {
long long int ctr = 0;
int a = A;
int b = B;
while(ctr < n + 1) {
cout << (a/b);
a = a%b;
int rem = 0;
while ( a < b ) {
a = a * 10;
if ( ctr == 0 && rem == 0 ) {
if ( n == 0 ) {
return;
}
cout <<".";
} else if ( rem ) {
cout << 0;
ctr++;
}
rem++;
}
ctr++;
}
}
void print(long long int n ) {
long long int ctr = 0;
if ( n == 0 ) {
cout << 3 << endl;
} else if ( n == 1 ) {
cout << "3.1" << endl;
} else {
int q = (n - 1)/51;
int rem = (n -1) % 51;
cout << "3.1";
for ( int i = 0; i < q; i++ ) {
cout << str;
}
for ( int i = 0; i< rem; i++ ) {
cout<< str[i];
}
cout << endl;
}
return;
}
int main()
{
int t;
cin >> t;
for ( int i = 0; i < t; i++ ) {
int n;
cin >> n;
print(n);
}
return 0;
}