A^B mod C

Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63).

Input

There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.

Output

For each testcase, output an integer, denotes the result of A^B mod C.

Sample Input

3 2 4
2 10 1000

Sample Output

1
24

我用的unsigned_int64开数据。用快速幂和快速乘写,注意:不要用%,会超时(大佬说的,并且我已经验证过了...233)

代码:

#include<stdio.h>
#define ull unsigned __int64
ull mul(ull a,ull b,ull c){
ull res=0;
a=a%c;
while(b){
if(b & 1) res+=a;
if(res>=c) res-=c; //代替%
b/=2;
a+=a;
if(a>=c) a-=c; //代替%
}
return res;
} int main(){
ull a,b,c,ans;
while(scanf("%I64u%I64u%I64u",&a,&b,&c)!=EOF){
ans=1;
a=a%c;
while(b){
if(b%2==1) ans=mul(ans,a,c);
a=mul(a,a,c);
b/=2;
}
printf("%I64u\n",ans);
}
return 0;
}

最新文章

  1. System.Security.Cryptography.CryptographicException,密钥集不存在
  2. Lisp中编写宏的步骤以及规范
  3. 初探JavaScript(三)——JS带我&quot;碰壁&quot;带我飞
  4. centos7 静态ip设置
  5. [整理]iOS开发学习
  6. 破解 RCA_CRACKME(解除隐藏按钮)
  7. 大并发连接的oracle在Linux下内存不足的问题的分析
  8. robotframework-FQA
  9. TableLayout
  10. Javascript判断数据类型与真假值隐形转换研究
  11. Redis与数据库同步问题
  12. 洛谷 P2073 送花【Treap】题解+AC代码
  13. CSS3选择器p:nth-child和p:nth-of-type之间的差异
  14. COMP9334 Project
  15. [GXOI/GZOI2019]旅行者
  16. ShowDoc上手
  17. Flask---第一个例子--使用Flask写的【Hello World !】的web程序
  18. qrCode二维码字符串长度太多压缩的问题
  19. JavaScript 函数式编程读书笔记1
  20. git从安装到使用

热门文章

  1. [16]Windows内核情景分析 --- 服务管理
  2. date的用法
  3. Sitecore CMS中更改项目的模板
  4. 20155228 实验五 Android开发基础
  5. VM VirtualBox 全屏模式 &amp;&amp; 自动缩放模式 相互切换
  6. python 查询文本文件的层次
  7. Axis2之Spring装配
  8. Collections集合工具类的方法
  9. 外网上传到NAS速度很慢是什么情况?上行1M都不到,但是测试有4M
  10. document.createDocumentFragment 以及创建节点速度比较