Cod sursa(job #538638)

Utilizator klamathixMihai Calancea klamathix Data 21 februarie 2011 19:38:11
Problema Suma divizorilor Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<cstdio>
const int mod = 9901;
using namespace std;

int i , a , b , n , ans;

int power (int b){
	int i , ans = 1 , n = a % mod;
	
	for( i = 0 ; (1 << i) <= b ; ++i ) {
		if ( b & (1 << i))
			ans *= n , ans %= mod;
		n *= n , n %= mod;
	}
return ans;
}

int sum (int b) {
	if ( b == 1 ) return a;
	if ( b & 1 )
		return (sum(b - 1) + power(b)) % mod;
	return (power(b / 2) + 1) * sum(b / 2) % mod;
}

int main()
{
	freopen("sumdiv.in","r",stdin);
	freopen("sumdiv.out","w",stdout);
	
	scanf("%d %d",&a,&b);

	printf("%d\n", (sum(b) + 1) % mod);
	
return 0;
}