【题目链接】

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

【算法】

快速幂

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; long long a,b,h,ans,T,p; template <typename T> inline void read(T &x)
{
long long f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x)
{
if (x < )
{
putchar('-');
x = -x;
}
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x)
{
write(x);
puts("");
}
inline long long power(long long a,long long n)
{
long long ans = ,b = a;
while (n)
{
if (n & ) ans = (ans * b) % p;
b = (b * b) % p;
n >>= ;
}
return ans;
} int main()
{ read(T);
while (T--)
{
ans = ;
read(p); read(h);
while (h--)
{
read(a); read(b);
ans = (ans + power(a,b)) % p;
}
writeln(ans);
} return ; }

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

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

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

  2. POJ 1995:Raising Modulo Numbers 快速幂

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

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

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

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

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

  5. poj 1995 Raising Modulo Numbers 题解

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

  6. poj1995 Raising Modulo Numbers【高速幂】

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

  7. 【POJ 3140】 Contestants Division(树型dp)

    id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS   Memory Limit: 65536K Tot ...

  8. 【POJ 1275】 Cashier Employment(差分约束系统的建立和求解)

    [POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS   Memory Limit: 10 ...

  9. 【POJ 2486】 Apple Tree(树型dp)

    [POJ 2486] Apple Tree(树型dp) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8981   Acce ...

随机推荐

  1. eclipse配置Tomcat服务器server locations的方法

    最近放弃了使用Myeclipse,转而使用eclipse作为开发工具,确实Myeclipse集成了太多东西,使得开发人员的配置越来越少,这不是个好事,使用eclipse后,有些地方就得自己去配置,比如 ...

  2. 09C语言指针

    C语言指针 地址 地址就是数据元素在内存中的位置表示: &变量名 #include <stdio.h> int main(){ int aa; unsigned int bb = ...

  3. react antD 日期选择

    <DatePicker disabledDate={disabledDate} onChange={this.onChange} /> //创建时间禁用大于当前时间 <moment( ...

  4. node-sass安装失败的解决方案

    这是一个老生常谈的问题了,网上有很多解决方法,找一个自己觉得合适的才是最重要的...... 执行以下命令即可: npm config set sass_binary_site https://npm. ...

  5. python_ 学习笔记(运算符)

    python的运算符基本和C语言一致,以下说一些不一样的! 算术运算符 **:代表乘方,对应也有**=: //:代表商向下取整,对应也有//=: 逻辑运算符 and or not 位运算符 :& ...

  6. ubuntu 常见的操作命令

    原博客地址为:https://blog.csdn.net/qq_33421080/article/details/76551554 1.cd命令: cd:切换到当前用户根目录,默认[/home/用户名 ...

  7. sql杂记:一些坑和数据库恢复

    这是一篇纯粹的乱七八糟的笔记...(勿喷)主要记录一下初入SQL坑的杂七杂八的注意事项. 一.先补充下事务的写法: start transaction;#开始事务 --各种事务... commit;# ...

  8. [bzoj1925][Sdoi2010][地精部落] (序列动态规划)

    Description 传说很久以前,大地上居住着一种神秘的生物:地精. 地精喜欢住在连绵不绝的山脉中.具体地说,一座长度为 N 的山脉 H可分 为从左到右的 N 段,每段有一个独一无二的高度 Hi, ...

  9. gif & tools

    gif & tools https://www.cockos.com/licecap/ https://www.cockos.com/licecap/licecap128-install.ex ...

  10. objective-c 通告

    1. 通告和委托的区别 通告也能传递与事件相关的数据.通告不同于委托的地方在于,通告是在对象执行完成动作之后产生,而不是之前.受到通告的对象没有机会建议是否要执行动作,而且对象的通告可以有多个监听者( ...