Cod sursa(job #2098355)

Utilizator flibiaVisanu Cristian flibia Data 2 ianuarie 2018 18:33:02
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.29 kb
#include <bits/stdc++.h>
#define mod 9973
#define ll long long
#define N 1000002

using namespace std;

ifstream in("ssnd.in");
ofstream out("ssnd.out");

int t, sum, nr, cnt;
ll x; 
vector <int> primes;
bool viz[1000100];

void mul(int &n, int val){
	n = (n * val) % mod;
}

void precalc(){
	for(int i = 2; i <= N; i++)
		if(!viz[i]){
			primes.push_back(i);
			for(int j = i + i; j <= N; j += i)
				viz[j] = 1;
		}	
}

int lgput(int a, int p){
	a %= mod;
	int rs = 1;
	while(p){
		if(p & 1)
			mul(rs, a);
		mul(a, a);
		p /= 2;
	}
	return rs;
}

void gcd(int a, int b, int &d, int &x, int &y){
	if(!b){
		d = a;
		x = 1;
		y = 0;
	} else{
		int xx, yy;
		gcd(b, a % b, d, xx, yy);
		x = yy;
		y = xx - yy * (a / b);
	}
}

int inv(int a){
	int b = mod, d, x, y;
	gcd(a, b, d, x, y);
	while(x < 0)
		x += mod;
	return x % mod;
}

void solve(){
	in >> x;
	sum = nr = 1;
	for(auto i : primes){
		if(1LL * i * i > x)
			break;
		cnt = 0;
		while(x % i == 0)
			cnt++, x /= i;
		if(cnt){
			nr *= cnt + 1;
			mul(sum, lgput(i, cnt + 1) - 1);
			mul(sum, inv(i - 1));
		}
	}
	if(x > 1){
		nr *= 2;
		mul(sum, (x + 1) % mod);
	}
	out << nr << ' ' << sum << '\n';
}

int main(){
	in >> t;
	precalc();
	while(t--)
		solve();
	return 0;
}