Easy Summation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 4112    Accepted Submission(s): 1676

Problem Description
You are encountered with a traditional problem concerning the sums of powers.
Given two integers n and k. Let f(i)=ik, please evaluate the sum f(1)+f(2)+...+f(n). The problem is simple as it looks, apart from the value of n in this question is quite large.
Can you figure the answer out? Since the answer may be too large, please output the answer modulo 109+7.
 
Input
The first line of the input contains an integer T(1≤T≤20), denoting the number of test cases.
Each of the following T lines contains two integers n(1≤n≤10000) and k(0≤k≤5).
 
Output
For each test case, print a single line containing an integer modulo 109+7.
 
Sample Input
3
2 5
4 2
4 1
 
Sample Output
33
30
10

题意:给出n,k,定义f(i)=i^k,求出[f(1)+f(2)+……+f(n)]mod 1e9+7

题解:直接套快速幂,注意用long long

 #include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+;
long long PowerMod(long long a, long long b,long long c) {
long long ans = ;
a = a % c;
while(b>) { if(b % == )
ans = (ans * a) % c;
b = b/;
a = (a * a) % c;
}
return ans;
}
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
long long n,k,sum=;
scanf("%lld %lld",&n,&k);
for(int i=;i<=n;i++)
{
sum+=PowerMod(i,k,mod);
sum=sum%mod;
}
printf("%lld\n",sum);
}
}
return ;
}

hdu6027Easy Summation(快速幂取模)的更多相关文章

  1. 【转】C语言快速幂取模算法小结

    (转自:http://www.jb51.net/article/54947.htm) 本文实例汇总了C语言实现的快速幂取模算法,是比较常见的算法.分享给大家供大家参考之用.具体如下: 首先,所谓的快速 ...

  2. HDU 1061 Rightmost Digit --- 快速幂取模

    HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...

  3. UVa 11582 (快速幂取模) Colossal Fibonacci Numbers!

    题意: 斐波那契数列f(0) = 0, f(1) = 1, f(n+2) = f(n+1) + f(n) (n ≥ 0) 输入a.b.n,求f(ab)%n 分析: 构造一个新数列F(i) = f(i) ...

  4. POJ3641-Pseudoprime numbers(快速幂取模)

    题目大意 判断一个数是否是伪素数 题解 赤果果的快速幂取模.... 代码: #include<iostream> #include<cmath> using namespace ...

  5. 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模

    题目地址:http://ac.jobdu.com/problem.php?pid=1085 题目描述: N<k时,root(N,k) = N,否则,root(N,k) = root(N',k). ...

  6. HDU--杭电--4506--小明系列故事——师兄帮帮忙--快速幂取模

    小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To ...

  7. CodeForces Round #191 (327C) - Magic Five 等比数列求和的快速幂取模

    很久以前做过此类问题..就因为太久了..这题想了很久想不出..卡在推出等比的求和公式,有除法运算,无法快速幂取模... 看到了 http://blog.csdn.net/yangshuolll/art ...

  8. HDU1013,1163 ,2035九余数定理 快速幂取模

    1.HDU1013求一个positive integer的digital root,即不停的求数位和,直到数位和为一位数即为数根. 一开始,以为integer嘛,指整型就行吧= =(too young ...

  9. Powmod快速幂取模

    快速幂取模算法详解 1.大数模幂运算的缺陷: 快速幂取模算法的引入是从大数的小数取模的朴素算法的局限性所提出的,在朴素的方法中我们计算一个数比如5^1003%31是非常消耗我们的计算资源的,在整个计算 ...

随机推荐

  1. POJ 1845 Sumdiv 【二分 || 逆元】

    任意门:http://poj.org/problem?id=1845. Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions ...

  2. 理解JavaScript的this对象

    1.概述 this对象是在运行时基于函数的执行环境绑定的,this总是返回一个对象,简单说,就是返回属性或方法"当前"所在的对象.在全局函数中,this等于window,而当函数作 ...

  3. Eclipse安装Sonarlint插件

    这里安装的是Sonarlint3.6.插件安装非常简单.插件比Sonar更为简单快捷. 一.首先通过点击Eclipse上方Help菜单会出现一个下拉列表,点击其中的Eclipse MarketPlac ...

  4. Windows 下制作CentOS7安装U盘

    本文属于另类的U盘制作方法(更多U盘安装见U盘安装CentOS ),如何安装CentOS,请参考<安装指南> 以下列出了,完整的制作步骤: 1.下载安装镜像 选择一个合适的镜像网站,比如网 ...

  5. VS2017无法打开Razor视图文件

    VS2017一直卡顿就在扩展和更新里把没用的插件关闭了.导致后来一直NETCORE的Razor视图文件打不开 查了资料才知道需要依赖 ASP.NET Core Razor Language Servi ...

  6. STM32之系统时钟

    转载:http://www.openedv.com/posts/list/302.htm 时钟系统是处理器的核心,所以在学习STM32所有外设之前,认真学习时钟系统是必要的,有助于深入理解STM32. ...

  7. Sublime text3学习小记(macOS系统下的安装使用)

    [注:以下内容参考https://blog.csdn.net/stilling2006/article/details/54376743] 一.认识Sublime text 1.一款跨平台代码编辑器, ...

  8. Android 发版的小工具

    Android加固包签名 我们知道自己的apk在上传市场的时候, 为了更好的包含我们的代码需要加固服务, 加固后的apk是不能直接安装的, 需要我们手动签名. 关于Android签名的知识就不在赘述了 ...

  9. redis存储数据的时候

    使用redis存储数据的时候,有时候为了查看的方便,通常会有层级或者说是目录, 这时候我们在set的时候,需要将key值使用“:”的符号来区分层级关系,比如:set(“a:b”, “123”),那么在 ...

  10. Flask—10-项目部署(02)

    项目部署 WEB工作原理 客户端(chrom) <=> WEB服务器(nginx) <=> WSGI(uWSGI) <=> Python(Flask) <=& ...