Sumdiv
Time limit:1000 ms |
|
Memory limit:30000 K |
Total submissions:13959 |
|
Accepted:3433 |
Description
Consider two natural numbers a and B. Let s be the sum of all natural divisors of a ^ B. Determine s modulo 9901 (the rest of the division of S by 9901 ).
Input
The only line contains the two natural numbers A and B, (0 <= A, B <= 50000000) separated by blanks.
Output
The only line of the output will contain in S modulo 9901.
Sample Input
2 3
Sample output
15
Hint
2 ^ 3 = 8.
The natural divisors of 8 are: 1, 2, 4, 8. Their sum is 15.
15 modulo 9901 is 15 (that shoshould be output ).
Source
Romania oi 2002
Thoughts:
http://hi.baidu.com/necsinmyway/item/9f10b6d96c5068fbb2f77740
AC code:
# Include <iostream> using namespace STD; # define ll long longll pow_mod (ll a, ll N, int mod) {// fast power ll r = 1; ll base =; while (n) {If (N & 1) r = r * base % MOD; base = base * base % MOD; n >>=1;} return R % 9901 ;} ll sum (ll a, LL B, ll mod) {// returns the first n of the proportional sequence and if (B = 0) return 1; if (B % 2 = 1) Return (sum (A, B/2, MoD) * (pow_mod (A, B/2 + 1, MoD) + 1 )) % MOD; else return (sum (A, B-1, MoD) + pow_mod (a, B, MoD) % MOD;} int main () {ll A, B; ll ans; while (CIN> A> B) {ans = 1; for (ll I = 2; I * I <= A; I ++) {// split a into the product of the prime number if (a % I = 0) {ll s = 0; while (a % I = 0) {s ++; a/= I;} ans = ans * sum (I % 9901, B * s, 9901) % 9901;} if (a> = 2) {ans = ans * sum (a % 9901, B, 9901) % 9901 ;}cout <ans <Endl ;}return 0 ;}