Cod sursa(job #2868884)

Utilizator QwertyDvorakQwerty Dvorak QwertyDvorak Data 11 martie 2022 11:19:29
Problema Suma si numarul divizorilor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 3.21 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define dbg(x) cout << #x <<": " << x << "\n";
using ll = long long;

class InP {

	FILE *fin;
	char *buff;
	int sp;
public:
	InP(const char *p) {
		fin = fopen(p, "r");
		buff = new char[4096]();
		sp = 4095;
	}

	char read_ch() {
		sp++;
		if (sp == 4096) {
			fread(buff, 1, 4096, fin);
			sp = 0;
		}
		return buff[sp];
	}

	InP& operator >> (int &n) {

		char c;
		int sgn = 1;
		while (!isdigit(c = read_ch()) && c != '-');

		if (c == '-') {
			n = 0;
			sgn = -1;
		}
		else n = c - '0';
		while (isdigit(c = read_ch()))
			n = n * 10 + c - '0';
		n = n * sgn;
		return *this;
	}

	InP& operator >> (ll &n) {

		char c;
		ll sgn = 1;
		while (!isdigit(c = read_ch()) && c != '-');

		if (c == '-') {
			n = 0;
			sgn = -1;
		}
		else n = c - '0';
		while (isdigit(c = read_ch()))
			n = n * 10 + c - '0';
		n = n * sgn;
		return *this;
	}


};




class OuP {

	FILE *fout;
	char *buff;
	int sp;

public:
	OuP(const char *p) {
		fout = fopen(p, "w");
		buff = new char[50000]();
		sp = 0;
	}
	~OuP() {
		fwrite(buff, 1, sp, fout);
		fclose(fout);
	}

	void write_ch(char c) {
		if (sp == 50000) {
			fwrite(buff, 1, sp, fout);
			sp = 0;
		}
		buff[sp++] = c;
	}

	OuP& operator << (int n) {
		if (n <= 9)
			write_ch(n + '0');
		else {
			*this << (n / 10);
			write_ch(n % 10 + '0');
		}
		return *this;
	}

	OuP& operator << (ll n) {
		if (n <= 9)
			write_ch(n + '0');
		else {
			*this << (n / 10);
			write_ch(n % 10 + '0');
		}
		return *this;
	}

	OuP &operator <<(char c) {
		write_ch(c);
		return *this;
	}
	OuP &operator << (const char *p) {
		while (*p) {
			write_ch(*p);
			p++;
		}
		return *this;
	}

};


InP fin("ssnd.in");
OuP fout("ssnd.out");

// ifstream fin("ssnd.in");
// ofstream fout("ssnd.out");

const int mod = 9973;

int t;

const int prmx = 1e6 + 4;
bitset<1000005> isprime;
vector<ll> primes;
void compPrime() {

	isprime[1] = isprime[0] = 1;
	for (int i = 4; i <= prmx; i += 2)
		isprime[i] = 1;
	for (int i = 3; i * i <= prmx; i += 2)
		if (!isprime[i])
			for (int j = i * i; j <= prmx; j += i + i)
				isprime[j] = 1;
	isprime.flip();
	for (ll i = 2; i <= prmx; i++)
		if (isprime[i])
			primes.pb(i);
}

ll expp(ll a, ll n) {
	ll p = 1;
	while (n) {
		if (n & 1)
			p = 1LL * p * a % mod;
		a = 1LL * a * a % mod;
		n >>= 1;
	}
	return p;
}

ll inv(ll x) {
	return expp(x, mod - 2) % mod;
}


void desc(ll n) {

	ll ans1, ans2;
	ans1 = ans2 = 1;

	for (int i = 0; i < primes.size() && 1LL * primes[i] * primes[i] <= n  && n > 1; i++) {
		if (n % primes[i] == 0) {
			ll e = 0;
			while (n % primes[i] == 0)
				n /= primes[i], e++;
			ans1 = (ans1 * 1LL * (e + 1));
			ans2 = ans2 * 1LL * (expp(primes[i], e + 1) - 1) % mod * inv(primes[i] - 1) % mod;
		}
	}

	if (n > 1) {
		ans1 = (ans1 * 2);
		ans2 = ans2 * 1LL * (1LL * n * n - 1) % mod * inv(n - 1) % mod;
	}

	fout << ans1 << ' ' << ans2 << '\n';

}


int main() {

	fin >> t;
	compPrime();
	while (t--) {
		ll x;
		fin >> x;
		desc(x);
	}

	// fin.close();
	// fout.close();
	return 0;
}