首页 > 其他 > 详细

快速幂模板

时间:2017-04-06 22:46:30      阅读:230      评论:0      收藏:0      [点我收藏+]
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 int f(int x,int n)
 6 {
 7     int now=1;
 8     while(n)
 9     {
10         if(n&1)
11         {
12             now=now*x;
13         }
14         x=x*x;
15         n>>=1;
16     }
17     return now;
18 }
19 int main()
20 {
21     int x,n;
22     cin>>x>>n;
23     cout<<f(x,n);
24     return 0;
25 }

 

快速幂模板

原文:http://www.cnblogs.com/zwfymqz/p/6675322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!