Cod sursa(job #1062292)

Utilizator andreas.chelsauAndreas Chelsau andreas.chelsau Data 21 decembrie 2013 00:14:29
Problema Suma divizorilor Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
#define modulo 9901

ll b[200],e[200];
int counter;

void primeFactors(ll n){

	if(n % 2 == 0){
		b[counter] = 2;
		n >>= 1;
		++e[counter];
		while(n % 2 == 0)
			++e[counter],n >>= 1;
		counter++;
	}
	ll p = 3;
	while(p * p <= n){
		if(n % p == 0){
			b[counter] = p;
			while(n % p == 0)
				n /= p,++e[counter];
			counter++;	
		}
		p += 2;
	}
	if (n > 1) 
	 b[counter] = n,e[counter++] = 1;
		
}
ll pow(ll a,ll b){
	ll res = 1;
	while (b)
	{
		if (b % 2)  
			res = (res * a) % modulo; 
		a = (a * a) % modulo;
		b >>= 1;
	}

	return res;
}
ll findInverse(ll a)
{
	ll b = modulo;
	ll b0 = b, t, q;
	ll x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}
ll calc(ll A,ll B){
	ll sum = 1;
	int i;
	primeFactors(A);
	for(i = 0; i < counter; i++)
		sum *= ((pow(b[i],(e[i] * B + 1)) + modulo - 1) % modulo) * ((findInverse(b[i] - 1) % modulo)),sum %= modulo;
	return sum;
}

int main(){
	freopen("sumdiv.in","r",stdin);
	freopen("sumdiv.out","w",stdout);
	ll A,B;
	scanf("%lld %lld", &A, &B);
	printf("%lld",calc(A,B));
	return 0;
}