http://acm.fzu.edu.cn/problem.php?pid=1752

http://acm.fzu.edu.cn/problem.php?pid=1650

给跪了。

我的快速幂会越界。。

学习学习大神们的方法。。位运算好强大~

以后干脆当模版用好了- -|||

  1. #include <cstdio>
  2. typedef unsigned long long LL;
  3. LL mod;
  4. LL mul(LL a,LL b,LL c) //用快速幂的思想求a*b%c防止越界
  5. {
  6. LL ret=0,tmp=a%c;
  7. while(b)
  8. {
  9. if(b&1)
  10. if((ret+=tmp)>=c)
  11. ret-=c;
  12. if((tmp<<=1)>=c)
  13. tmp-=c;
  14. b>>=1;
  15. }
  16. return ret;
  17. }
  18. void pow_mod(LL a,LL n)
  19. {
  20. LL ret=1;
  21. while(n) //a^n %mod
  22. {
  23. if(n & 1)
  24. ret=mul(ret,a,mod);
  25. a=mul(a,a,mod);
  26. n>>=1;
  27. }
  28. printf("%llu\n",ret);
  29. }
  30.  
  31. int main()
  32. {
  33. LL a,b;
  34. while(~scanf("%llu%llu%llu",&a,&b,&mod))
  35. {
  36. pow_mod(a,b);
  37. }
  38. return 0;
  39. }

FZU 1650 1752 a^b mod c的更多相关文章

  1. 福州大学oj 1752 A^B mod C ===>数论的基本功。位运用。五星*****

    Problem 1752 A^B mod C Accept: 579    Submit: 2598Time Limit: 1000 mSec    Memory Limit : 32768 KB P ...

  2. [FOJ 1752] A^B mod C

    Problem 1752 A^B mod C Accept: 750    Submit: 3205Time Limit: 1000 mSec    Memory Limit : 32768 KB   ...

  3. FZU 1752 A^B mod C(快速加、快速幂)

    题目链接: 传送门 A^B mod C Time Limit: 1000MS     Memory Limit: 65536K 思路 快速加和快速幂同时运用,在快速加的时候由于取模耗费不少时间TLE了 ...

  4. FZU 1759 Super A^B mod C 指数循环节

    Problem 1759 Super A^B mod C Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description G ...

  5. FZU 1759-Super A^B mod C

    传送门:http://acm.fzu.edu.cn/problem.php?pid=1759 Accept: 1161    Submit: 3892Time Limit: 1000 mSec     ...

  6. FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...

  7. FZU Super A^B mod C(欧拉函数降幂)

    Problem 1759 Super A^B mod C Accept: 878    Submit: 2870 Time Limit: 1000 mSec    Memory Limit : 327 ...

  8. Day7 - B - Super A^B mod C FZU - 1759

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

  9. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

随机推荐

  1. 【D3 API 中文手冊】

    [D3 API 中文手冊] 声明:本文仅供学习所用,未经作者同意严禁转载和演绎 <D3 API 中文手冊>是D3官方API文档的中文翻译. 始于2014-3-23日,基于VisualCre ...

  2. 9.Maven之(九)依赖关系

    转自:https://yq.aliyun.com/ziliao/312160 在maven的管理体系中,各个项目组成了一个复杂的关系网,但是每个项目都是平等的,是个没有贵贱高低,众生平等的世界,全球每 ...

  3. Java学习笔记八

    IO流:就是input/output输入/输出流. 一.字节流操作文件的便捷类:FileWriter和FileReader import java.io.FileWriter; import java ...

  4. 三、Docker镜像的相关操作

    原文:三.Docker镜像的相关操作 一.查看本地镜像: docker images 二.使用某个镜像来运行容器: docker run -t -i xxxx(镜像名):xx.xx(版本,不带即最新) ...

  5. Unity5中的粒子缩放(附测试源码)

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/49363241 作者:car ...

  6. 代码生成器实现的Entity,Dao,Service,Controller,JSP神器(含代码附件)

    package com.flong.codegenerator; import java.sql.Connection; import java.sql.DatabaseMetaData; impor ...

  7. Objective-C - 类的静态常量

    创建头文件(.h), 导出常量: // Constants.h FOUNDATION_EXPORT NSString *const MyFirstConstant; FOUNDATION_EXPORT ...

  8. Android判断App是否在前台运行

    版权声明:本文为博主原创文章,未经博主允许不得转载. //当前应用是否处于前台 private boolean isForeground(Context context) { if (context ...

  9. event事件对象 兼容写法:var oEvent=ev||event;和取消事件冒泡

    要在整个页面添加事件要使用document,例如要捕抓鼠标位置 document.onclink=function(ev)  //FireFox Chrome默认都是有一个值传进来的 { var oE ...

  10. golang sort

    package main import ( "fmt" "strings" "sort" ) type Animals []string f ...