山东省第八届 ACM 省赛 sum of power (求和、水)

网友投稿 578 2022-10-03

山东省第八届 ACM 省赛 sum of power (求和、水)

山东省第八届 ACM 省赛 sum of power (求和、水)

Problem Description

Calculate ∑ni=1im mod (1000000000+7)

Input

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

Output

Output the answer in a single line.

Example Input

10 0

Example Output

10

思路

绝不应该错的一道题,比赛时第一道敲的题目,居然 ​​1WA​​​ 了,原因时题面上写的 ​​mod=100000000+7​​​ ,当时已经写出 ​​1e9+7​​​ ,然后检查的时候发现差点交错,改成 ​​1e8+7​​ 之后就错了。

还好之后这道题重判了,减少了20分钟的罚时。

会不会 100000000+7=1e9+7 呢?

AC 代码

#include#include#include#include#include#includeusing namespace std;#include#include#define eps (1e-8)const int mod = 1e9+7;typedef long long LL;LL mult(LL a,LL n){ LL ans=1; while(n) { if(n&1)ans=(ans*a)%mod; a=(a*a)%mod; n>>=1; } return ans;}int main(){ LL n,m; while(cin>>n>>m) { LL ans=0; for(LL i=1; i<=n; i++) ans=(ans+mult(i,m))%mod; cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:小程序怎么把富文本转换为文本
下一篇:SpringBoot集成drools的实现示例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~