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. MyBatis(9)整合spring

    具体的感兴趣可以参考:MyBatis 此时此刻,没用的话不再多说了,直接开始代码工程吧! 整体的代码实现: 具体使用到的我们在进行细说 基本上理解一边就能会使用整合  准备工作:  db.proper ...

  2. StringJoiner

    示例一 public class StringJoinerTest1 { public static void main(String[] args) { StringJoiner joiner = ...

  3. Vue教程:过滤器filters(五)

    Vue.js 允许你自定义过滤器,可被用于一些常见的文本格式化.过滤器可以用在两个地方:双花括号插值和 v-bind 表达式 (后者从 2.1.0+ 开始支持).过滤器应该被添加在 JavaScrip ...

  4. 在EF Core里面如何使用以前EntityFramework的DbContext.Database.SqlQuery<SomeModel>自定义查询

    问: With Entity Framework Core removing dbData.Database.SqlQuery<SomeModel> I can't find a solu ...

  5. LeetCode18.四数之和 JavaScript

    给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满 ...

  6. java模拟浏览器发送请求

    package test; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOExcep ...

  7. 【Linux资源管理】使用sar进行性能分析

    sar可用于监控Linux系统性能,帮助我们分析性能瓶颈.sar工具的使用方式为”sar [选项] intervar [count]”,其中interval为统计信息采样时间,count为采样次数. ...

  8. mysql数据库迁移到oracle数据库后 如何删除相同的数据

    mysql数据库迁移到oracle数据库后 如何删除相同的数据 首先搞清楚有多少数据是重复的 select pid from product group by pid having count(pid ...

  9. obfuscator-llvm Theos 集成配置

    之前我写过一篇文章是关于在 Xcode 里怎么集成配置 obfuscator-llvmobfuscator-llvm Xcode集成配置 有些情况下我们使用 Theos 开发 tweak,需要将 ob ...

  10. Centos7 安装ipython 和 ipython3

    [root@localhost ~]# wget https://pypi.python.org/packages/79/63/b671fc2bf0051739e87a7478a207bbeb45cf ...