题目链接:http://poj.org/problem?id=1995

解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可。

#include<stdio.h>
long long quick_mod(long long a,long long b,long long c)
{
long long ans=1;
while(b)
{
if(b&1)
{
ans=ans*a%c;
}
b>>=1;
a=a*a%c;
}
return ans;
}
int main()
{
int ncase;
int m,h;
int i;
long long a,b,s;
scanf("%d",&ncase);
while(ncase--)
{
s=0;
scanf("%d",&m);
scanf("%d",&h);
for(i=1;i<=h;i++)
{
scanf("%lld %lld",&a,&b);
s=(s+quick_mod(a,b,m))%m;
}
printf("%I64d\n",s);
}
}

POJ 1995 Raising Modulo Numbers 【快速幂取模】的更多相关文章

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

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

  2. Raising Modulo Numbers_快速幂取模算法

    Description People are different. Some secretly read magazines full of interesting girls' pictures, ...

  3. POJ1995:Raising Modulo Numbers(快速幂取余)

    题目:http://poj.org/problem?id=1995 题目解析:求(A1B1+A2B2+ ... +AHBH)mod M. 大水题. #include <iostream> ...

  4. POJ 1995 Raising Modulo Numbers

    快速幂取模 #include<cstdio> int mod_exp(int a, int b, int c) { int res, t; res = % c; t = a % c; wh ...

  5. POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]

    传送门:http://poj.org/problem?id=1845 大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有 ...

  6. POJ 1995:Raising Modulo Numbers 快速幂

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

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

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

  8. POJ1995 Raising Modulo Numbers(快速幂)

    POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...

  9. poj 1995 Raising Modulo Numbers 题解

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

随机推荐

  1. <轉>APUE:mmap函数

    起初 看过一遍内存映射I/O,意思大概是懂了,就是直接操作文件再而直接通过缓冲区来操作,减少一些read.write调用所花费的时间.加上文中给出一个copy的例子,意思也好理解的.不过困扰的来了,我 ...

  2. Linux 中文件名颜色所代表的属性

    1. 白色:表示一般文件 2. 蓝色:表示目录 3. 绿色:表示可执行的文件或程序 4. 浅蓝色:表示链接文件 5. 黄色:表示设备文件 6. 灰色:表示其他类型文件 7. 红色:表示压缩文件或者包文 ...

  3. apiCloud中aui获取不到高度,pos.h为0,offsetHeight为0问题

    apiCloud中aui获取不到高度,pos.h为0,offsetHeight为0问题 原HTML <div class="row aui-text-center"> ...

  4. 点击之后上传图片到页面 input type="file" 样式

    <!DOCTYPE html><head> <meta http-equiv="Content-Type" content="text/ht ...

  5. php进程控制

    1 POSIX扩展    posix_access($file,$mode)  查看文件的访问权限,可以由is_readable等几个函数代替    posix_errno()  返回posix函数执 ...

  6. 序列模型(4)----门控循环单元(GRU)

    一.GRU 其中, rt表示重置门,zt表示更新门. 重置门决定是否将之前的状态忘记.(作用相当于合并了 LSTM 中的遗忘门和传入门) 当rt趋于0的时候,前一个时刻的状态信息ht−1会被忘掉,隐藏 ...

  7. Laravel的路由功能

    只能在当前方法内加载视图和URL跳转!

  8. CentOS 笔记(二) 端口占用,进程查看

    ①查看当前端口情况 netstat -nultp ②查看当前进程情况 ps -ef ps -ef|grep dotnet ③强制kill 进程 kill -9 [PIN]

  9. LVM实践

    [root@ftp:/root] > fdisk -l Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = ...

  10. 出现$ref的原因及解决方案

    $ref的产生原因 (1)重复引用:一个集合/对象中的多个元素/属性都引用了同一个对象 (2)循环引用:集合/对象中的多个元素/属性在相互引用导致循环 针对fastjson的处理 fastjson作为 ...