ASUMHARD - A Summatory (HARD)
f(n) is defined as: f(n) = 1k+2k+3k+ ... +nk, so it is the sum of the k-th power of all natural numbers up to n.
In this problem you are about to compute,
f(1) + f(2) + f(3) + ... + f(n)
Input
The first line is an integer T (1 ≤ T ≤ 54,321), denoting the number of test cases. Then, T test cases follow.
For each test case, there are two integers n (1 ≤ n ≤ 123,456,789) and k (0 ≤ k ≤ 321) written in one line, separated by space.
Output
For each test case output the result of the summatory function described above.
Since this number could be very large, output the answer modulo 1,234,567,891.
Example
Input: 5
2 3
10 3
3 3
100 0
100 1 Output: 10
7942
46
5050
171700
Warning: A naive algorithm may not run in time
hide comments
Blasters:
2014-05-20 15:04:45
@Tjandra Can you please tell why i am getting tle ID NO 11612132 I used O(t*k) + k^2 algo with fast i/o and on ideone the worst case runs in 4.5 sec Last edit: 2014-05-20 15:05:12 |
|
(Tjandra Satria Gunawan)(曾毅昆):
2014-02-09 22:57:40
@Francky: Congratulations :)
|
|
Francky:
2014-02-08 14:39:17
Fast IO bring me from 0.63 to 0.47, and first place. ;-). I liked work on this problem, I should have done the job before.
|
|
abdou_93:
2013-07-19 22:19:26
Why TLE ??!!!!!!
|
|
abdelkarim:
2013-07-16 01:59:11
by using Faulhaber's Triangle and some optimization i think i can solve this one in O(k^2) algo .
|
|
Michael Kharitonov:
2013-03-07 08:11:21
Nice one, "Concrete Mathematics" rocks again! Finally beat Mitch ;-)
|
|
15972125841321:
2012-07-22 14:36:18
@tajandra dude awesome problem had to optimize a whole lot of things to get an AC..
|
|
TINYJR:
2012-07-13 14:45:34
I don't think k^2 is fast enough to AC this problem. Last edit: 2012-06-21 13:43:32 |
|
devu:
2012-07-13 14:45:34
enjoyed solving it.. nice problem
|
|
krishnan:
2012-07-13 14:45:34
How to approach this problem using Matrix exponentation. Can anyone give a hint.
|
Added by: | Tjandra Satria Gunawan |
Date: | 2012-06-07 |
Time limit: | 2.107s |
Source limit: | 12345B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM32-GCC ASM64 MAWK BC C-CLANG NCSHARP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET |
Resource: | Harder version of A Summatory problem. |