【题目链接】

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. CodeFrist基础

    Code First(代码先行).它思想就是先定义模型中的类,再通过这些类生成数据库.这种开发模式适合于全新的项目,它使得我们可以以代码为核心进行设计而不是先构造数据库. EF中创建数据库的表必须要有 ...

  2. XML中的特殊(保留)字符数据

    XML中的特殊(保留)字符数据 制作人:全心全意 在XML文档中,有些字符会被XML解析器当作标记进行处理.如果希望把这些字符作为普通字符处理,就需要使用实体引用或CDATA段. 使用实体引用 为了避 ...

  3. HDU 5178 pairs(双指针)

    HDU 5178 pairs(双指针) Hdu 5178 解法:因为要求的是绝对值小于等于k,因此数字的序号关系并不重要,那么排序后使用双指针即可解决这个问题. #include<queue&g ...

  4. PAT 1139 First Contact

    Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle i ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. iOS攻城狮修炼之路

    自己总结的学习iOS的笔记,打造一个全面的知识体系,iOS攻城狮修炼之路[持续更新中] iOS学习笔记01-APP相关 iOS学习笔记02-UIScrollView iOS学习笔记03-UITable ...

  7. [K/3Cloud]实现双击列表行后显示具体的某个单据明细。

    列表插件重写void ListRowDoubleClick(ListRowDoubleClickArgs e)事件,在事件中处理具体逻辑,具体代码如下 public override void Lis ...

  8. PatentTips - Hamming distance comparison

    BACKGROUND INFORMATION In a typical data processing environment, data may be transmitted in multiple ...

  9. HashMap源码分析3:移除

    本文源码基于JDK1.8.0_45. final Node<K,V> removeNode(int hash, Object key, Object value, boolean matc ...

  10. MFC ActiveX新增属性页 控件不响应

    在Activex中可以添加自定义的属性页,在新的属性页上添加一个button控件,设置好响应函数后,测试时发现点击button没有响应. 对比之前的主属性页发现,新增属性页的属性“Disabled” ...