zoukankan      html  css  js  c++  java
  • ACdream 1007 (快速幂)

    题目链接

    a + b

    Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

    Problem Description

    Input

    Output

    Sample Input

    2
    3 1
    1 2 3
    3 10
    1 2 3

    Sample Output

    6
    60074
    
    
    /*************************************************************************
        > File Name: 1007.cpp
        > Author: Stomach_ache
        > Mail: sudaweitong@gmail.com
        > Created Time: 2014年08月11日 星期一 07时44分39秒
        > Propose: 
     ************************************************************************/
    #include <cstdio>
    /*Let's fight!!!*/
    
    typedef long long LL;
    const LL mod = (LL)1e10 + 7;
    
    LL mul(LL a, LL b) {
          LL res = 0;
        while (b) {
              if (b&1) if ((res += a) >= mod) res -= mod;
            a <<= 1;
            if (a >= mod) a -= mod;
            b >>= 1;
        }
        return res;
    }
    
    LL mod_pow(LL a, LL b) {
          LL res = 1;
        while (b) {
              if (b&1) res = mul(res, a);
            a = mul(a, a);
            b >>= 1;
        }
        return res;
    }
    
    int main(void) {
        int t;
        scanf("%d", &t);
        while (t--) {
            LL n, k, ans = 0, x;
            scanf("%lld %lld", &n, &k);
            k %= 9560995488LL;
    
            for (int i = 0; i < n; i++) {
                scanf("%lld", &x);
                ans += mod_pow((x%mod+mod)%mod, k);
                if (ans >= mod) ans -= mod; 
            }
    
            printf("%lld
    ", ans);
        }
    
        return 0;
    }
    
    
    
    
    
    
    
  • 相关阅读:
    架构笔记七
    架构笔记六
    架构笔记五
    架构笔记四
    python2与python3的区别
    萌新VRTK学习(四)攀爬系统
    萌新VRTK学习(三)物体的抓取
    萌新VRTK学习(二)移动
    萌新VRTK学习(一)VRTK的配置
    C#委托事件随笔
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3904074.html
Copyright © 2011-2022 走看看