Submeter | Todas submissőes | Melhores | Voltar |
Problem hidden
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
Adicionado por: | Tjandra Satria Gunawan |
Data: | 2012-06-07 |
Tempo limite: | 2.107s |
Tamanho do fonte: | 12345B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Linguagem permitida: | ADA95 ASM32 GAWK BASH BF C CSHARP C++ 4.3.2 CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN GO HASK ICON ICK JAVA JS-RHINO LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON PYTHON3 RUBY SCM guile SCM qobi SED ST WHITESPACE |
Origem: | Harder version of A Summatory problem. |