题目描述
输入n,牛牛想知道0.5的n次方的精确值。 注意是精确值,也就是小数有多少位,就要输出多少位,不四舍五入。(当然也不输出多余的0) 对于100%的数据,1 <= n <= 1000 对于60%的数据,1 <= n <= 27 对于30%的数据,1 <= n <= 4
输入描述:
输入一行一个整数n。
输出描述:
输出0.5的n次方的精确值。
示例1
输入
2
输出
0.25
示例2
输入
77
输出
0.00000000000000000000000661744490042422139897126953655970282852649688720703125
说明
精确值
开个数组存每一位有点像高精度
#include<bits/stdc++.h>
using namespace std;
int i,m,n,j,k,a[1000001],b[10001];
char c[10001];
void cheng(int *a,int *b)
{int t[100001];memset(t,0,sizeof(t));for(int i=1;i<=a[0];i++)for(int j=1;j<=b[0];j++) t[i+j-1]+=a[i]*b[j],t[i+j]+=t[i+j-1]/10,t[i+j-1]%=10;a[0]=a[0]+b[0];while(!t[a[0]]) a[0]-=1;for(int i=1;i<=a[0];i++)a[i]=t[i];
}
void ksm(int n)
{a[0]=1;a[1]=5;b[0]=1;b[1]=1;for(n;n>1;n>>=1){if(n&1) cheng(b,a);cheng(a,a);}cheng(a,b);
}
int main()
{scanf("%d",&n);ksm(n);printf("0.");int k=n;for(k;k>a[0];k--) printf("0");for(i=a[0];i>=1;i--) printf("%d",a[i]);return 0;
}
来源:nkw