码迷,mamicode.com
首页 > 编程语言 > 详细

Java的快速幂

时间:2018-03-18 20:04:31      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:pow   scanner   turn   ret   void   col   generate   ati   pos   

 1 import java.util.Scanner;
 2 
 3 public class C {
 4     public static long power(int x,int n) {
 5         if(n == 0)
 6             return 1;
 7         long t = power(x,n/2);
 8         t = t*t;
 9         if(n%2 == 1)
10             t = t*x;
11         return t;
12     }
13     public static void main(String[] args) {
14         // TODO Auto-generated method stub
15         Scanner in = new Scanner(System.in);
16         int x,n;
17         x = in.nextInt();
18         n = in.nextInt();
19         long t = power(x,n);
20         System.out.println(t);
21     }
22 
23 }

 

Java的快速幂

标签:pow   scanner   turn   ret   void   col   generate   ati   pos   

原文地址:https://www.cnblogs.com/xuyanqd/p/8596712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!