zoukankan      html  css  js  c++  java
  • 2017年ACM第八届山东省赛G题:sum of power

    G: sum of power

    题目描述

    Calculate  mod (1000000000+7) for given nm.

    输入

    Input contains two integers n,m(1≤n≤1000,0≤m≤10).

    输出

    Output the answer in a single line.

    样例输入

    10 0

    样例输出

    10
    
    题意:累加从 1 到 n 的 m次幂模
    思路:不用快速幂都能过 还要什么思路。。。。。
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
     
    using namespace std ; 
     
    #define mod 1000000007
    #define LL long long
     
    LL quick_mod(LL n , LL m){
        LL result = 1 ; 
        while(m){
            if(m&1){
                result = (result * n )%mod ; 
            }
            n = (n*n) %mod; 
            m>>=1 ; 
        }
        return result %mod; 
    }
     
    int main(){
        int n , m ; 
        while(~scanf("%d%d" , &n , &m)){
            LL result = 0  ; 
            for(int i=1 ; i<=n ; i++){
                result = (result+quick_mod(i , m) ) %mod ; 
            }
            printf("%lld
    " , result) ; 
        }
        return 0 ; 
    } 
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std ;

    #define LL long long
    #define mod 1000000007
    int main(){
        LL n , m ;
        while(~scanf("%lld%lld" , &n , &m)){
            LL result = 0 ;
            for(int i=1 ; i<= n ; i++){
                LL num = 1 ;
                for(int j=1 ; j<=m ; j++){
                    num = num * i %mod ; // i ^ m % mod
                }
                result = (result + num ) % mod ;
            }
            printf("%lld " , result) ;
        }    
        return 0 ;
    }
    
    
  • 相关阅读:
    【NOIP2013】花匠
    【DP合集】tree-knapsack
    【DP合集】m-knapsack
    【DP合集】背包 bound
    【DP合集】合并 union
    【DP合集】棋盘 chess
    BZOJ1026 [SCOI2009]windy数
    最长上升子序列 LIS nlogn
    再谈线性基
    数论问题算法模板
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/7631592.html
Copyright © 2011-2022 走看看