上完厕所后,蒜头君的手机欠费了,因而他来到了中国移动营业厅。正当他准备交钱时,忽然发现钱包不见了。html
“奇怪,今天出门时明明带了钱包。”蒜头君自言自语道。ios
“别着急,今天推出了一个新活动。只要计算出这道题的答案,就送 999999 元话费”工做人员指着一块公告牌耐心地说。ide
只见公告牌上写着,计算 1^{2019}+2^{2019}+3^{2019}+\ldots+n^{2019}12019+22019+32019+…+n2019 对 1008610086 取模的结果,其中 n=10^{12}n=1012。ui
请你帮助蒜头君计算答案。spa
题解:debug
由于 n^2019 = (n%10086)^2019,因此每10086个数的2019次方的和都是相等的htm
即 ans = 1^2019+2^2019+...+10086^2019 = 10087^2019+10088^2019+...+2*10086^2019blog
所以10^12中有n^12/10086个完整周期,这些完整周期的和是单个周期和ans乘以周期数ip
最后再加上不足一个周期的其余数的和就是答案string
#include <map> #include <set> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define ls (r<<1) #define rs (r<<1|1) #define debug(a) cout << #a << " " << a << endl using namespace std; typedef long long ll; const ll maxn = 1e6+10; const ll mod = 10086; const double pi = acos(-1.0); const double eps = 1e-8; ll qow( ll a, ll b ) { ll ans = 1; while( b ) { if( b&1 ) { ans = ans*a%mod; } a = a*a%mod; b /= 2; } return ans; } int main() { ll ans = 0, t = 1e12; for( ll i = 1; i <= mod; i ++ ) { ans = (ans+qow(i%mod,2019))%mod; } ans = ans*(t/mod)%mod; t = t%mod; for( ll i = 1; i <= t; i ++ ) { ans = (ans+qow(i%mod,2019))%mod; } cout << ans << endl; return 0; }