Cod sursa(job #807435)

Utilizator Sanduleac_VladSanduleac Vllad Alexandru Sanduleac_Vlad Data 4 noiembrie 2012 18:37:32
Problema GFact Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.37 kb
#include <stdio.h>

long long x, n;
long p, q;
bool k = 1;

int main() {
	long i, j;
	freopen("gfact.in", "r", stdin);
	freopen("gfact.out", "w", stdout);
	scanf("%ld %ld", &p, &q);
	x = (long long)p * q;
	n = 1;
	for(i = 1; i <= q && k; i++) {
		n *= p;
		for(j = 1; n * j <= x; j++)
			if(i + n * j <= x)
				x -= i;
	}
	printf("%lld", x);
	return 0;
}