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

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

给跪了。

我的快速幂会越界。。

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

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

#include <cstdio>
typedef unsigned long long LL;
LL mod;
LL mul(LL a,LL b,LL c) //用快速幂的思想求a*b%c防止越界
{
LL ret=0,tmp=a%c;
while(b)
{
if(b&1)
if((ret+=tmp)>=c)
ret-=c;
if((tmp<<=1)>=c)
tmp-=c;
b>>=1;
}
return ret;
}
void pow_mod(LL a,LL n)
{
LL ret=1;
while(n) //a^n %mod
{
if(n & 1)
ret=mul(ret,a,mod);
a=mul(a,a,mod);
n>>=1;
}
printf("%llu\n",ret);
} int main()
{
LL a,b;
while(~scanf("%llu%llu%llu",&a,&b,&mod))
{
pow_mod(a,b);
}
return 0;
}

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. Webservice银行报文接口设计

      Preface: 合理的软件架构设计其好处是不言而喻的,系统具有清晰的软件结构,良好的可扩展性,类的职能单一明确,系统的复杂度底.此前的一个实际项目中总结了些关于OO设计的实际应用,主要是围绕'高 ...

  2. libssh2进行远程运行LINUX命令

    /** * CSSHClient.h * @file 说明信息.. * DATE February 13 2015 * * @author Ming_zhang */ #ifndef _CSSHCLI ...

  3. 小胖说事29-----iOS中Navigation中左滑pop页面的三种方法

    第三中类型.自己定义任何位置返回页面的方式,上边的类就是.m,大家能够贴过去使用.这个类是继承NavigationController的.用这个类初始化rootController就能够了.这里还有源 ...

  4. java 位操作 bitwise(按位) operation bit

    java 位操作 bitwise(按位) operation bit //一篇对于 原码 反码 补码 的介绍 http://www.cnblogs.com/zhangziqiu/archive/201 ...

  5. golang excel

    github.com/tealeg/xlsx 封装的接口简单易用 package main import ( "bufio" "fmt" "githu ...

  6. Flask项目之手机端租房网站功能测试(完结)

    说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 目录 一丶注册和登录以及用户退出功能 二丶上传头像功能和修改用户名功能测试 三丶发布房源以及实名认证功能测试 四丶网站房屋搜索功能 ...

  7. android:一个Open键引发的问题!!

    1.问题简单介绍 首先描写叙述一下问题.当我们安装完APP的时候,界面会显示两个button,一个完毕键,一个Open键,点击Open键之后.进入应用.此时.我们点击HOME键.程序将会后台.然后再点 ...

  8. 【MongoDB】The connection between two tables

    In mongoDB, there are two general way to connect with two tables. Manual Connection and use DBRef 1. ...

  9. Java缓存组件 EhCache 入门教程

    1.技术背景: 系统缓存是位于应用程序与物理数据源之间,用于临时存放复制数据的内存区域,目的是为减少应用程序对物理数据源访问的次数,从而提高应用程序的运行性能.缓存设想内存是有限的,缓存的时效性也是有 ...

  10. 【Educational Codeforces Round 33 C】 Rumor

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然最后会形成多个集合,每个集合里面的人能够可以互相到达. 则维护并查集的时候,顺便维护一下每个集合里面的最小值就好. 最后答案就为 ...