鏈接:https://www.nowcoder.com/acm/contest/118/B
來源:牛客網
題目描述
喜愛ACM的PBY同學遇到了一道數學難題,已知底數n,請你幫他準確的計算出結果a = nπ(n的π次方),結果保留小數點後x位。
輸入描述:
第一行是一個整數t,表示測試實例的個數;
然後是t行輸入數據,每行包含兩個正整數n和x,表示底數和保留位數。
(1 <= t <= 100,1 <= n <= 500,1 <= x <= 6)
輸出描述:
對於每組輸入數據,分別輸出結果a,每個輸出佔一行。
示例1
輸入
3
1 3
7 6
9 1
輸出
1.000
451.807873
995.0
思路
字面描述,只是開的π
不能太小
代碼
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double pi=3.1415926535897932384626433;
const double e=2.718281828459;
int main()
{
int t,x;
double m,su;
cin >> t;
while(t--)
{
cin >> m >> x;
su=exp(pi*log10(m)/log10(e));
printf("%.*lf\n",x,su);
}
return 0;
}