zoukankan      html  css  js  c++  java
  • POJ1995 Raising Modulo Numbers(快速幂)

    POJ1995 Raising Modulo Numbers

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

      快速幂,套模板

      

    /*
    * Created:     2016年03月30日 23时01分45秒 星期三
    * Author:      Akrusher
    *
    */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <set>
    #include <map>
    #include <stack>
    #include <queue>
    #include <numeric>
    #include <iomanip>
    #include <bitset>
    #include <sstream>
    #include <fstream>
    using namespace std;
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=n-1;i>=a;i--)
    #define in(n) scanf("%d",&(n))
    #define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
    #define inll(n) scanf("%I64d",&(n))
    #define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
    #define inlld(n) scanf("%lld",&(n))
    #define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
    #define inf(n) scanf("%f",&(n))
    #define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
    #define inlf(n) scanf("%lf",&(n))
    #define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
    #define inc(str) scanf("%c",&(str))
    #define ins(str) scanf("%s",(str))
    #define out(x) printf("%d
    ",(x))
    #define out2(x1,x2) printf("%d %d
    ",(x1),(x2))
    #define outf(x) printf("%f
    ",(x))
    #define outlf(x) printf("%lf
    ",(x))
    #define outlf2(x1,x2) printf("%lf %lf
    ",(x1),(x2));
    #define outll(x) printf("%I64d
    ",(x))
    #define outlld(x) printf("%lld
    ",(x))
    #define outc(str) printf("%c
    ",(str))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define SZ(x) ((int)(x).size())
    #define mem(X,Y) memset(X,Y,sizeof(X));
    typedef vector<int> vec;
    typedef long long ll;
    typedef pair<int,int> P;
    const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
    const int INF=0x3f3f3f3f;
    ll mod;
    ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}//快速幂计算
    const bool AC=true;
    
    
    int main()
    {
        int t,n;
        ll ans,a,b;
        in(t); //别忘了输入
        while(t--){
        inlld(mod);
        in(n);
        ans=0;
        rep(i,0,n){
        inlld2(a,b);
        ans=(ans+powmod(a,b))%mod;
        }
        outlld(ans);
        }
        return 0;
    }
  • 相关阅读:
    filter, map, reduce, zip函数
    schwartzian sort
    各种排序
    MVVM
    js/jquery学习笔记(附百度统计初探??)
    由一句需求引发的mysql崩溃说起
    高效前端优化工具Fiddler入门教程
    由一次很有意思的购物体验想到的
    个人电脑文件目录变更日志小程序
    浅谈COOKIE和SESSION关系和区别等
  • 原文地址:https://www.cnblogs.com/akrusher/p/5339416.html
Copyright © 2011-2022 走看看