Cod sursa(job #804249)

Utilizator mazaandreiAndrei Mazareanu mazaandrei Data 29 octombrie 2012 14:58:10
Problema Suma divizorilor Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include<fstream>
#define M 9901
#define ULL unsigned long long
using namespace std;
int a,b,k,p[50],d[50],x;
ifstream f("sumdiv.in"); ofstream g("sumdiv.out");
int put(ULL a, ULL b){
	ULL val=1;
	for(ULL i = b; i; i>>=1)
    {
        if(i & 1) val = (val * a ) % M;
        a = (a * a) % M;
    }
	return val%M;
}
int main(){
	f>>a>>b;
	x=2;
	while(x*x<=a)
	{
		if(a%x==0)
		{
			++k; d[k]=0; p[k]=x;
			while(a%x==0){
				a/=x; d[k]++;
			}
			d[k]*=b;
		}
		++x;
	}

	if(a>1){ ++k; p[k]=a;d[k]=b;}
	int q=1;
	for(int i=1;i<=k;++i){
		int w=put(p[i],d[i]+1)-1;
		int e=put(p[i]-1,9899);
		q=(q*w*e)%M;
	}
	g<<q<<'\n';
	return 0;
}
	/*
	#include<fstream>
#define M 1999999973
#define ULL unsigned long long
using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.out");

ULL n, p;

int main()
{
    f>>n>>p;
    ULL val = 1;
    for(ULL i = p; i; i>>=1)
    {
        if(i & 1) val = (val * n ) % M;
        n = (n * n) % M;
    }
    g<<val<<'\n';

    g.close();
}
	*/