码迷,mamicode.com
首页 > 其他好文 > 详细

fastpower

时间:2018-01-15 11:00:03      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:div   using   ret   clu   pow   name   奇数   pac   post   

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 using namespace std;
 5 int ans,n=1012,k;
 6 int fastpower(int x,int y){//x^y%n
 7     ans=1;
 8     k=x%n;
 9     while(y){
10         if(y%2)//y是奇数
11             ans=(ans*k)%n;
12         k=(k*k)%n;
13         y=y/2;
14     }
15     return ans;
16 }
17 int main(){
18     int a,b,c;
19     cin>>a;
20     for(int i=0;i<a;i++){
21         scanf("%d%d",&b,&c);
22         printf("%d\n",fastpower(b,c));
23     }
24     return 0;
25 }

 

fastpower

标签:div   using   ret   clu   pow   name   奇数   pac   post   

原文地址:https://www.cnblogs.com/al76/p/8286651.html

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