POJ 1995 Raising Modulo Numbers
2016-04-12 09:03
330 查看
快速幂取模
#include<cstdio> int mod_exp(int a, int b, int c) { int res, t; res = 1 % c; t = a % c; while (b) { if (b & 1) res = res * t % c; t = t * t % c; b >>= 1; } return res; } int main() { int T; scanf("%d",&T); while(T--) { int m,h; scanf("%d%d",&m,&h); int ans=0; for(int i=1; i<=h; i++) { int a,b; scanf("%d%d",&a,&b); ans=(ans+mod_exp(a,b,m))%m; } printf("%d\n",ans); } return 0; }
相关文章推荐
- 用Foxmail for Mac客户端登录网易163邮箱
- LINQ的Contains方法
- LeetCode 70. Climbing Stairs
- 转载时请表明原文出处(http://blog.sina.com.cn/wyw1976)及作者邮箱(wyw1976@gmail.com) Linux 系统中有关mtd和u
- Visual Voicemail
- 小Ai成功预测我是歌手依靠的是什么
- A Head Start on Domain-Driven Design Patterns
- Communicating With Users and Developers - Mailing
- 发运确认后,订单行保持“已挑库”状态 Order Line Remains in Picked (Awaiting Shipping) Status After Ship Confirmation
- 【AC自动机/fail树】BZOJ3172- [Tjoi2013]单词
- Apache James配置个人笔记(完整解决DNS问题), 网页版的参考 Claros In Touch webmail(Pop3/IMAP)
- LeetCode Climbing Stairs 70
- Z-Stack分析--zmain_vdd_check()
- MySQL导入.sql文件时出现" failed to open file"错误
- HDFS源码分析之EditLogTailer
- codeforce 606C Sorting Railway Cars
- 赋予人工智能记忆的人,带你梳理深度学习核心算法
- Codeforces Beta Round #8 A. Train and Peter KMP
- Aizu 0189 Convenient Location【floyd】
- Component SAP_GWFND is locked against OCS package