题意:求出1^m+2^m+...n^m
思路:直接套用模板
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<stack> #include<ctype.h> #define LL long long using namespace std; const LL mod=1e9+7; LL bitlen(LL x) { LL d=0; while(x>0) { x>>=1; d++; } return d; } LL bitat(LL x,LL i) { return (x&(1<<(i-1))); } LL module(LL a,LL b,LL n) { LL i,y=1; for(int i=bitlen(b);i>0;i--) { y=(y*y)%n; if(bitat(b,i)>0) y=(y*a)%n; } return y; } int main() { LL n,m; while(scanf("%lld %lld",&n,&m)!=EOF) { LL ans=0; for(LL i=1;i<=n;i++) { ans+=module(i,m,mod); } ans=ans%mod; printf("%lld\n",ans); } return 0; }