precise math function

Time limit: 1 second for C/C++, 2 seconds for other languages
Space limit: C/C++ 32768K, other languages ​​65536K
64bit IO Format: %lld

Topic description 

A PBY student who loves ACM has encountered a mathematical problem. Knowing the base n, please help him accurately calculate the result a = n π (n to the power of π), and keep the result with x digits after the decimal point.

Enter description:

The first line is an integer t, indicating the number of test instances;
Then there are t lines of input data, each line containing two positive integers n and x, representing the base and the number of reserved digits.
(1 <= t <= 100,1 <= n <= 500,1 <= x <= 6)

Output description:

For each set of input data, output the result a separately, and each output occupies one line.
Example 1

enter

3
1 3
7 6
9 1

output

1.000
451.807873
995.0

Solution: It's ok to find it directly with the formula, pay attention to the accuracy of π, don't define it as 3.14159267.... can't pass. Use acos(-1) to represent π, because cosπ=-1. Using the inverse trigonometric function in high numbers to express π is

acos(-1). The rest is just a direct calculation.

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
intmain()
{
    int t,n,x;
    cin>>t;
    while(t--)
    {
        cin>>n>>x;
        cout<<fixed<<setprecision(x)<<pow(n,pi)<<endl;
    }
    return 0;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325685195&siteId=291194637