AFSK - Power Factor Sum Sum (hard)
Here is a mixed edition of Divisor Summation Powered and Amazing Factor Sequence (medium).
The powered factor sequence
For k an integer number, we define our powered factor sequence with:
ak[0] = 0; ak[1] = 1, and
for n > 1, ak[n] = ak[n - 1] + sum({x^k | 0 < x ≤ n and n % x = 0}).
Input
First line of input contains an integer T, the number of test cases.
Each of the next T lines contains three integers n, k, m.
Output
For each test case, print ak[n] on a single line. As the answer could be a big number, you just have to output it modulo m.
Example
Input: 3 3 1 10 4 2 55 5 3 97 Output: 8 37 43
Constraints
0 < T < 101
0 < n < 10^9
0 < k < 11
1 < m < 10^17
Numbers n, k, m are uniform-randomly chosen. For your information, there's two input files, the first one is 'easy' with n≤100. My (1kB)-python code get AC around 0.96s. I have a much slower basic PIKE AC (4.8s). (Edit 2017-02-11 ; timings and TL updated after compiler changes)
hide comments
[Lakshman]:
2014-11-15 19:57:55
Finally Accepted !!!!!!!!! after such a long time.
|
|
Sandeep Pathry:
2013-06-21 08:46:18
@francky... got AC...
|
|
fR0DDY:
2013-06-19 17:30:12
Again need help in bringing it closer to at least 5 secs. It's 10 times slower than your best. :(
|
|
Thomas Dybdahl Ahle:
2013-05-07 13:09:58
I don't get it. Isn't this exactly equal to calculating G(0,n,k) in IITD4?
|
|
maaz:
2013-04-27 16:30:43
with the given constraints i must say a really good question.. |
|
[Lakshman]:
2013-04-26 09:11:08
Why WA...It should be TLE but here I am getting WA...
|
|
Michael Kharitonov:
2013-03-21 10:06:43
It's brilliant! When I publish empty comment, it says "Comment too long!"
|
|
[Rampage] Blue.Mary:
2013-03-20 14:04:25
@Francky: Is my current C++ solution the expected one?
|
|
Ehor Nechiporenko:
2013-03-20 12:54:34
Okay, dokay, the first version was done, now I can optimize it as well. I need to find some good algo of fastest modular multiplication to make it as better as possible. Current version makes my code 10 times slower((
|
|
Francky:
2013-03-19 09:47:07
I have new timings in Python, it's easier to find new ideas (and it's not over...). Those ideas will help me to try a ultra fast C edition. Woohooo.
|
Added by: | Francky |
Date: | 2013-03-17 |
Time limit: | 15s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |