利用位乘,然后叠加
package coker;
import java.util.Scanner;
/**
* Created by TaoHaoWei on 2017/9/23.
* 本人新建博客:www.mynight.top
* 欢迎交友和指正 ^_^
* 滴滴,幂运算
*/
public class OutMi {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true)
{
String R = in.next();
int n = in.nextInt();
int flo = R.length()-R.indexOf(".")-1;
R = R.replace(".","");
StringBuilder sum = caculater(R.toCharArray(),n);
flo *= n;
flo = sum.length()-flo;
sum.insert(flo,".");
System.out.println(sum.toString());
}
}
private static StringBuilder caculater(char[] r, int n) {
int[] tmp = new int[r.length*2];
StringBuilder sb = new StringBuilder();
for (int i=0;i<r.length;i++)
sb.append(r[i]);
char[] zhu = r;
while (n-->1)
{
int flag = tmp.length;
int tt = 0;
for (int i=zhu.length-1;i>=0;i--)
{
int t = 1;
for(int j=r.length-1;j>=0;j--)
{
tmp[flag-t-tt] += (r[j]-'0')*(zhu[i]-'0');
t++;
}
tt++;
}
for (int i=tmp.length-1;i>=0;i--)
{
if(tmp[i]>9)
{
tmp[i-1] += tmp[i]/10;
tmp[i] %= 10;
}
}
sb = new StringBuilder();
int fir = 0;
for (int i=0;i<tmp.length;i++)
{
if(fir==0&&tmp[i]==0)
{
}else{
fir++;
sb.append(tmp[i]);
}
}
zhu = sb.toString().toCharArray();
tmp = new int[zhu.length+r.length];
}
return sb;
}
}