Question Link
This question is difficult to figure out !!!
Div (X, B)/MoD (X, B) = K (1 <= k <= ). Calculate the sum of X
Analysis:
We know that MoD (X % B) has a value range of 1-(b-1 ). We can solve the problem from this point ..
MoD (X, B) = 1, x = B + 1, 2B + 1, 3B + 1... a * B + 1.
MoD (X, B) = 2, x = 2B + 2, 4B + 2, 6B + 2 ,..... 2a * B + 2. = 2 (B + 1), 2 (2B + 1), 2 (3B + 1 )...... 2 (A * B + 1 ).
....
MoD (X, B) = B-1 ..
The equation can be converted into: x = K * Mod (X, B) * B + Mod (X, B ).
Enumeration 1-b-1. We can find that every sub-formula is an arithmetic difference sequence: ANS + = (A * (2 * I + I * a * B + I * B)/2; but we can find SA,B(1 digit ≤ DigitA, Bytes,BLimit ≤ limit 107 ).
In the middle of the multiplication, it will exceed LL, and this formula is used to divide the division of 2. In fact, there must be at least one even number in the two multiplier "ai * ()". Just find and divide the two.
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <queue> 6 #include <cmath> 7 #include <algorithm> 8 #define LL __int64 9 const int mo = 1e9+7;10 const int maxn = 100+10;11 using namespace std;12 LL a, b;13 14 int main()15 {16 LL i;17 LL ans;18 while(~scanf("%I64d%I64d", &a, &b))19 {20 ans = 0;21 for(i = 1; i < b; i++)22 {23 if((a*i)%2==0)24 {25 LL tmp = (a*i/2)%mo;26 ans += (((2+a*b+b)%mo)*tmp)%mo;27 ans %= mo;28 }29 else30 {31 LL tmp = ((2+a*b+b)/2)%mo;32 ans += ((a*i%mo)*tmp)%mo;33 ans %= mo;34 }35 }36 printf("%I64d\n", ans);37 }38 return 0;39 }
Codeforces round #272 (Div. 2) C. dreamoon and sums (mathematical thinking)