快速幂取模

#include<cstdio>

int mod_exp(int a, int b, int c)
{
int res, t;
res = % c;
t = a % c;
while (b)
{
if (b & ) res = res * t % c;
t = t * t % c;
b >>= ;
}
return res;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,h;
scanf("%d%d",&m,&h);
int ans=;
for(int i=; i<=h; i++)
{
int a,b;
scanf("%d%d",&a,&b);
ans=(ans+mod_exp(a,b,m))%m;
}
printf("%d\n",ans);
}
return ;
}

POJ 1995 Raising Modulo Numbers的更多相关文章

  1. poj 1995 Raising Modulo Numbers【快速幂】

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5477   Accepted: ...

  2. poj 1995 Raising Modulo Numbers 题解

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6347   Accepted: ...

  3. POJ 1995 Raising Modulo Numbers 【快速幂取模】

    题目链接:http://poj.org/problem?id=1995 解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可. #include<stdio.h> lon ...

  4. POJ 1995 Raising Modulo Numbers(快速幂)

    嗯... 题目链接:http://poj.org/problem?id=1995 快速幂模板... AC代码: #include<cstdio> #include<iostream& ...

  5. POJ 1995 Raising Modulo Numbers (快速幂)

    题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL ...

  6. Raising Modulo Numbers(POJ 1995 快速幂)

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5934   Accepted: ...

  7. 【POJ - 1995】Raising Modulo Numbers(快速幂)

    -->Raising Modulo Numbers Descriptions: 题目一大堆,真没什么用,大致题意 Z M H A1  B1 A2  B2 A3  B3 ......... AH  ...

  8. POJ 1995:Raising Modulo Numbers 快速幂

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5532   Accepted: ...

  9. POJ1995 Raising Modulo Numbers

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6373   Accepted: ...

随机推荐

  1. OpenGL与vs编程——error C2440: “glMaterialfv”: 无法从“GLfloat”转换为“const GLfloat *”

    void setMaterial(const GLfloat mat_diffuse[4],GLfloat mat_shininess){static const GLfloat mat_specul ...

  2. UIScreen的scale属性

    用来表示显示屏的像素密度与点坐标系统之间的关系.通过该属性,我们可以把视图中逻辑坐标系统里的点坐标转换成设备的物理像素坐标.在配有Retina显示屏的设备中,scale值是2.0,而在非Retina显 ...

  3. 初识Selenium(二)

    ---------------------------------------------------------------------------------------------------- ...

  4. mapreduce 依赖组合

    mport java.io.IOException;import java.util.StringTokenizer; import org.apache.hadoop.conf.Configurat ...

  5. 使用Github搭建个人博客网站

    1 新建一个repo,创建一个没有父节点的分支gh-pages(github规定,只有该分支中的页面,才会生成网页文件): mkdir jekyll_demo cd jekyll_demo git i ...

  6. 转:HTML错误编号大全

    HTML错误编号大全 状态行包含HTTP版本.状态代码.与状态代码对应的简短说明信息.在大多数情况下,除了Content-Type之外的所有应答头都是可选的.但Content-Type是必需的,它描述 ...

  7. android 5.0新特性学习--视图轮廓

    ViewOutlineProvider -- 视图轮廓setOutlineProvider--可以使用View.setClipToOutline方法去剪切一个视图的outline区域.只有rectan ...

  8. messages exchanged between the client's and server's computers will never be lost, damaged, or received out of order. [1]

    w几乎所有的HTTP通信都由TCP/IP承载. HTTP The Definitive Guide Just about all of the world's HTTP communication i ...

  9. HTTP代理浅说

    简单的说HTTP代理就是处于HTTP客户端和服务器端之间,中转消息的中间人. 一种代理是代客户端去请求服务器,叫做Forward Proxy正向代理:另一种是代理真正的服务器来接收用户请求,叫做Rev ...

  10. ice grid 第一篇

    关键点: (1)如果想提高并发的话,还是在一个node上对于同一个application开多个server instance. 1.名词解释 .Replica groups A replica gro ...