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

Input

The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing an integer M (1 <= M <= 45000). The sum will be divided by this number. Next line contains number of players H (1 <= H <= 45000). Next exactly H lines follow. On each line, there are exactly two numbers Ai and Bi separated by space. Both numbers cannot be equal zero at the same time.

Output

For each assingnement there is the only one line of output. On this line, there is a number, the result of expression

(A1B1+A2B2+ ... +AHBH)mod M.

快速幂,裸题:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
long long Deal(long long a, long long b, int mod)
{long long ans = 1;while(b){if(b & 1)ans = ans*a%mod;b /= 2;a = (a*a)%mod;    }    return ans;
}
int main()
{int t;scanf("%d", &t);while(t--){int mod, h;long long a, b, sum = 0;scanf("%d %d", &mod, &h);for(int i = 0; i < h; i++){scanf("%lld %lld", &a, &b);sum += Deal(a, b, mod) % mod; }printf("%lld\n", sum%mod);}return 0;
} 

转载于:https://www.cnblogs.com/soTired/p/4755988.html

Poj1995--Raising Modulo Numbers(快速幂)相关推荐

  1. poj 1995 Raising Modulo Numbers 二分快速幂

    题意:给定n对Ai,Bi,求所有Ai的Bi次方之和对M取模的结果: 思路:二分法求快速幂: #include<cstdio> #include<cstring> #includ ...

  2. 【poj1995】Raising Modulo Numbers

    problem T组数据,每组包含n对ai,bi和一个p. 每组输出一个答案,∑ni=1aibi%p∑i=1naibi%p \sum_{i=1}^n ai^{bi} \%p. solution 快速幂 ...

  3. Raising Modulo Numbers

    http://poj.org/problem?id=1995 题解:快速幂 /* *@Author: STZG *@Language: C++ */ //#include <bits/stdc+ ...

  4. 【POJ - 1995】Raising Modulo Numbers(裸的快速幂)

    题干: People are different. Some secretly read magazines full of interesting girls' pictures, others c ...

  5. c语言的幂乘积表达式,POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]

    大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有且只有一种方式写出其素因子的乘积表达式. ,其中 为素数 2) 约数和 ...

  6. [矩阵乘法/快速幂专题]Arc of Dream,Recursive sequence,233 Matrix,Training little cats

    矩阵快速幂习题 复习矩阵乘法及快速幂模板 乘法模板 快速幂模板 T1:Arc of Dream 题目 题解 code T2:Recursive sequence 题目 题解 code T3:233 M ...

  7. `Computer-Algorithm` 数论基础知识 (同余,取模,快速幂,质数,互质,约数,质因子)

    catalog 同余 取模 快速幂 质数 互质 约数 质因子 @Delimiter(旧解释) 经验谈 两数之差也整除 加一的特殊性 取模 累加的周期性 取模的唯一集合 取模下的四则运算 除法的不可约性 ...

  8. 矩阵快速幂2Jzzhu and Sequences Recurrences Contemplation! Algebra Reading comprehension

    来!接着写题解,立个flag:矩阵快速幂题解不写完今晚不睡觉! 此题解是接着矩阵快速幂1写的,此篇有哪里写不清楚的地方导致看不懂的可以先看1:https://blog.csdn.net/qq_4536 ...

  9. 等比数列求和 (快速幂 + 逆元)

    求一个等比数例之和, 并让他对一个数取模. 用到等比数列求和公式, 快速幂, 逆元. 不会证明, 下面给出代码. #include <stdio.h> #include <strin ...

最新文章

  1. 21天精通python-21天学通Python 完整pdf扫描版[58MB]
  2. boost::base_from_member相关的测试程序
  3. 做好数据挖掘模型的9条经验总结
  4. 定时创建oracle索引,oracle数据库关于索引建立及使用的详细介绍
  5. 干货|基于 Spring Cloud 的微服务落地
  6. 负载均衡层设计方案(2)——Nginx安装
  7. HTML页面的基本代码结构是什么?
  8. 从旧版升级到MySql4.1上的中文乱码问题解决方案
  9. Matlab 简单图像分割实战
  10. 机械盘阵高并发——使用ImDisk 与 junction显著提高整体吞吐性能
  11. php 怎么使用api付款,使用PHP中的REST API进行Paypal付款
  12. 互联网创业技术团队需要多少人
  13. Python笔记相关
  14. JAVA 构造方法、无参构造方法、有参构造方法、构造方法重载
  15. Python实战之小说下载神器(二)整本小说下载:看小说不用这个程序,我实在替你感到可惜*(小说爱好者必备)
  16. 去售楼处看房需要了解哪些楼盘信息
  17. linux下运行win10效果好不好,Win10不好用?继续坚守Win7的人依然巨多
  18. 国内首个,成都智算中心成东数西算应用混合方案的数据中心样板
  19. 详解一个Python库,用于构建精美数据可视化web app,练习做个垃圾分类app
  20. 2017年5月许小年最新演讲:深圳人没房的,还是咬咬牙就买吧!

热门文章

  1. Python--print用法汇总
  2. php ajax勾选框提交,jQuery选取所有复选框被选中的值并用Ajax异步提交数据的实例...
  3. c语言根据变量作用域不同分为,C语言中不同变量的访问方式
  4. cglib和asm相关的文章
  5. 在javascript中调用java
  6. VB案例:计算圆锥体积与面积
  7. OpenCV学习笔记04:在Visual Studio上使用OpenCV4.5.5
  8. 大数据学习笔记42:Hive - 分桶表
  9. Python学习笔记:爬取网页图片
  10. 一阶电路中的时间常数_你知道RC电路和RL电路中时间常数的来源么?