Most of the explanations are as follows:
Http://hi.baidu.com/timer/item/ebc8c7ef908085215b2d6476
Question:
(1 ^ B + 2 ^ B +... + A ^ B) %
1 ≤ A ≤ 1000000000, 1 ≤ B ≤ 1000000000
Ideas:
A and B have a large range. It is certainly not possible to directly calculate or directly use a rapid power modulo.
Note the question condition: B must be an odd number.
Observe the original formula and find [C ^ B + (a-c) ^ B] % A = 0.
(Proof: Just split (a-c) ^ B with the binary theorem)
So it is easy: When a is an odd number, the original formula is 0; When a is an even number, the original formula is = (a/2) ^ B %. and then quickly modulo out the solution.
Click it by yourself:
#include <cstdio>using namespace std;typedef long long ll;int mod;ll mypow(ll a, ll n){ ll ret = 1; while(n) { if(n%2) ret = (ret*a)%mod; a = (a*a)%mod; n >>= 1; } return ret;}int cal(int a, int b){ if(a&1) return 0; return mypow(a/2,b);}int main(){ int a,b; while(scanf("%d %d",&a,&b)==2) { mod = a; printf("%d\n",cal(a,b)); }}
It's still a pattern...