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 ;
    }
    
    
  • 相关阅读:
    从零开始webpack4.x(五) js处理
    从零开始webpack4.x(四)样式loader
    从零开始webpack4.x(三)html插件
    从零开始webpack4.x(二)基础
    从零开始webpack4.x(一)介绍
    【转】react和vue渲染流程对比
    css3相关
    html5相关
    this指向
    整数划分问题(递归)
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/7631592.html
Copyright © 2011-2022 走看看