Cod sursa(job #1870663)

Utilizator pas.andreiPopovici Andrei-Sorin pas.andrei Data 6 februarie 2017 20:18:48
Problema Suma divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <bits/stdc++.h>
#define MOD 9901
#define pb push_back
#define INF 0x3f3f3f3f
#define INFLL (1LL*INF*INF)
#define ll long long

using namespace std;

typedef pair<int, int> pii;

ifstream fin("sumdiv.in");
ofstream fout("sumdiv.out");

inline int powlog(int x, int y) {
	int i,a=x%MOD,ans=1;

	for(i=0;(1<<i)<=y;++i) {
		if(y&(1<<i)) ans=(ans*a)%MOD;

		a=(a*a)%MOD;
	}

	return ans;
}

int main() {
	int a,b,d,nr,res=1;

	fin>>a>>b;

	d=2;
	while(d*d<=a) {
		nr=0;
		if(a%d!=0) {
			d++;
			continue;
		}
		while(a%d==0) {
			a/=d;
			++nr;
		}

		res=(res*(powlog(d,nr*b+1)-1))%MOD;
		res=(res*powlog(d-1,MOD-2))%MOD;
		++d;
	}

	if(a!=1) {
		if(a%MOD==1)
			res=(1LL*res*(1+b))%MOD;
		else {
			res=(res*(powlog(a,b+1)-1))%MOD;
			res=(res*powlog(a-1,MOD-2))%MOD;
		}
	}

	while(res<0) res+=MOD;
	fout<<res;

	return 0;
}