次方求模
时间限制:1000ms | 内存限制:65535KB难度:3
- 描述
- 求a的b次方对c取余的值
- 输入
- 第一行输入一个整数n表示测试数据的组数(n<100)
每组测试只有一行,其中有三个正整数a,b,c(1=<a,b,c<=1000000000) - 输出
- 输出a的b次方对c取余之后的结果
- 样例输入
-
3 2 3 5 3 100 10 11 12345 12345
- 样例输出
-
3 1 10481
- 来源
- [张云聪]原创
- 上传者
- 张云聪
- 这题可以当做模板题
- View Code
1 2 /********************************* 3 / Problem: 4 / Algorithm: 5 / Language: C++ 6 / Compiler: MinGW 7 / Date: 12/08/08 8 / 9 / Copyright (C) wujianwei 10 / All rights reserved. 11 ********************************/ 12 13 #include <iostream> 14 #include <cstdio> 15 #include <cstring> 16 #include <cmath> 17 #include <vector> 18 #include <cstring> 19 #include <queue> 20 #include <stack> 21 #include <algorithm> 22 #include <set> 23 24 using namespace std; 25 26 #define INF 0x7fffffff 27 #define EPS 1e-12 28 #define MOD 1000000007 29 #define PI 3.141592653579798 30 #define N 100005 31 const int MAX=1<<28; 32 typedef long long LL; 33 //typedef __int64 INT 34 35 LL poww(LL a,LL b,LL c) 36 { 37 LL ans=1,t=a; 38 while(b) 39 { 40 if(b&1) ans=ans*t%c; 41 t=t*t%c; 42 b>>=1; 43 } 44 return ans; 45 } 46 47 int main() 48 { 49 int T; 50 LL a,b,c; 51 scanf("%d",&T); 52 while(T--) 53 { 54 //scanf("%lld%lld%lld",&a,&b,&c); 55 cin>>a>>b>>c; 56 cout<<poww(a,b,c)<<endl; 57 } 58 return 0; 59 } 60
原文链接: https://www.cnblogs.com/wujianwei/archive/2012/08/13/2637008.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/59115
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!