山东省第八届ACM省赛 G 题 sum of power 解答
来源:互联网 发布:c语言之父 编辑:程序博客网 时间:2024/06/12 00:37
sum of power
Time Limit: 1000MSMemory Limit: 65536KB
Problem Description
Calculate mod (1000000000+7) for givenn,m.
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
题意
很明确,不必多说
思路
比如说,998^10 显然无法计算,所以不能用求出准确值的方法 然后进行取模,必须在过程中进行取模运算。显然,大数取模,想到快速幂(很重要,可以作为公式备注)。(注意,此题不是 多输入,白白WA了一次)。
AC代码: g++ 0ms
#include<iostream>#include<cstdio> //AC 0ms#include<cstring>#include<cmath>const int mod = 1e9+7 ;using namespace std;int n,m;long long sum;long long pow_mod(int a,int n,int m)//快速幂,a为底数,n为幂次,m为mod数;{ if(n==0) return 1; long long x=pow_mod(a,n/2,m); long long ans=(long long)x*x%m; if(n%2==1) ans=ans*a%m; return ans; //返回值是 余数}int main(){ scanf("%d%d",&n,&m); sum=0; for(int i=1;i<=n;i++){ sum+=pow_mod(i,m,mod); //循环累加过程 sum=sum%mod; } cout<<sum<<endl; //用cout输出,避免 lld 或者I64d 的编译区分 return 0;}
stut 3899
阅读全文
1 0
- 山东省第八届ACM省赛 G 题 sum of power 解答
- 山东省第八届ACM省赛 G 题(sum of power)
- 山东省第八届 ACM 省赛 G sum of power (简单快速幂)
- 山东省第八届 ACM 省赛 sum of power (求和、水)
- 山东省第八届 ACM 省赛 sum of power(SDUT 3899)
- 第八届山东省赛题->sum of power
- 山东省第八届ACM省赛 J 题 company(两种思路) 解答
- 山东省第八届ACM省赛 K 题 CF 解答(未完,待续)
- 山东省第八届ACM省赛G和J
- 山东省第八届acm大赛 G题 (SDUT 3899)
- 山东省第八届ACM省赛C题
- 山东省第八届ACM省赛A题
- 山东省第八届ACM省赛A.Return of the Nim
- 山东省第八届acm省赛 Return of the Nim
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛G
- 山东省第八届acm省赛C题 巨坑
- 山东省第八届acm省赛A题 博弈
- 山东省第八届ACM省赛 I 题(Parity check)
- html5怎样调用手机摄像头或者相册
- 小白学tkinter(事件之(事件序列))
- C++中int型与string型互相转换
- 从一道编程题看JS字符串连接性能
- 调整Linux的网络栈(Buffer Size)来提升网络性能
- 山东省第八届ACM省赛 G 题 sum of power 解答
- API之信息隐藏
- 已知栈的压入顺序,判断弹出顺序是否正确
- 史上最全的maven的pom.xml文件详解
- bootstrap popover与a标签点击事件冲突,需要点击两下才能显示问题
- angularjs获取cookies的token
- 操作系统学习_编译和写入_nasm dd
- 引用变量的初始化
- Django->Ajax 传输参数和接受参数方式