Cod sursa(job #208483)

Utilizator alex_mircescuAlex Mircescu alex_mircescu Data 16 septembrie 2008 19:14:05
Problema Suma divizorilor Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <stdio.h>
#include <math.h>

long long n, x, y, i, j, a[1000], b[1000];
long long s, s2, z;

long long proc(long long x, long long y) {
	long long t = 1;   
	for (long k = y; k > 1; k >>= 1) {   
		if (k % 2 == 1) {
			t = (t * x) % 9901;   
		}
		x = (x * x) % 9901;   
	}   
	return t;
}

int main() {
	freopen("sumdiv.in", "r", stdin);
	freopen("sumdiv.out", "w", stdout);
	scanf("%lld %lld", &x, &y);
	for (i = 2; i * i <= x; ++i) {
		if (x % i > 0) {
			continue;
		}
		a[++n] = i;
		while (x % i == 0) { 
			x /= i; 
			++b[n]; 
		}
	}
	if (x > 1) { 
		a[++n] = x; 
		b[n] = 1; 
	}
	s = 1;
	for (i = 1; i <= n; ++i) {
		b[i] *= y; 
		if (a[i] % 9901 == 1) {
			z = b[i]+1;
		} else {
			z = (proc(a[i], b[i]) * a[i] + 9900) % 9901;
			z = (z *proc(a[i] - 1, 9901 - 2)) % 9901;
		} 
		s = (s * z) % 9901;
	}
	printf("%lld\n", s);
	return 0;
}