利用位乘,然后叠加 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; } }
点赞 1

相关推荐

不愿透露姓名的神秘牛友
11-21 17:16
科大讯飞 算法工程师 28.0k*14.0, 百分之三十是绩效,惯例只发0.9
点赞 评论 收藏
分享
双非坐过牢:非佬,可以啊10.28笔试,11.06评估11.11,11.12两面,11.19oc➕offer
点赞 评论 收藏
分享
牛客网
牛客企业服务