• 【POJ 1995】 Raising Modulo Numbers


    【题目链接】

               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 = 1; x = 0;
        char c = getchar();
        for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
        for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
        x *= f;
    }
    template <typename T> inline void write(T x)
    {
        if (x < 0)
        {
            putchar('-');
            x = -x;
        }
        if (x > 9) write(x/10);
        putchar(x%10+'0');
    }
    template <typename T> inline void writeln(T x)
    {
        write(x);
        puts("");
    }
    inline long long power(long long a,long long n)
    {
            long long ans = 1,b = a;
            while (n)
            {
                    if (n & 1) ans = (ans * b) % p;
                    b = (b * b) % p;
                    n >>= 1;    
            }    
            return ans;
    }
    
    int main() 
    {
            
            read(T);
            while (T--)
            {
                    ans = 0;
                    read(p); read(h);
                    while (h--)
                    {
                            read(a); read(b);
                            ans = (ans + power(a,b)) % p;
                    }
                    writeln(ans);
            }
            
            return 0;
        
    }
  • 相关阅读:
    五、MapReduce 发布服务
    四、MapReduce 基础
    三、Hadoop 的 API
    二、HDFS 架构
    php身份证号的验证
    php性能优化
    PHP网站开发方案
    php一个不错的分页
    2013年最流行的php框架盘点
    程序员之路
  • 原文地址:https://www.cnblogs.com/evenbao/p/9233515.html
Copyright © 2020-2023  润新知