# Cod sursa(job #631382)

Utilizator Data 7 noiembrie 2011 21:45:30 Suma si numarul divizorilor 100 cpp done Arhiva educationala 2.64 kb
``````#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cfloat>
#include <numeric>

using namespace std;

const int    oo  = 0x3f3f3f3f;
const double eps = 1e-9;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(c) int ((c).size())
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define FORIT(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define mp make_pair
#define pb push_back
#define MAX_N 1 << 20
#define MOD 9973

unsigned char p[MAX_N];
int primes[MAX_N], K;

void sieve () {
for (int i = 2; i * i < MAX_N; ++i) if (p[i] != 1)
for (int k = i * i; k < MAX_N; k += i) p[k] = 1;
FOR (i, 2, MAX_N) if (p[i] != 1) primes[K++] = i;
}

ll exp_mod(ll a, ll x, ll m) {
if (x == 0) return 1;
ll res = exp_mod(a, x/2, m);
res = (res * res) % m;
return (x % 2) ? (res * a) % m : res;
}

ll inverse(ll a, ll p) {
return exp_mod(a, p-2, p);
}

ll factor (ll p, ll d) {
ll oldp = p;

ll u = 1;
p %= MOD;

for (; d; d >>= 1) {
if (d & 1) {
u *= p;
u %= MOD;
}

p *= p;
p %= MOD;
}

u = (u - 1 + MOD) % MOD;

return u * inverse(oldp - 1, MOD);
}

int main () {
freopen ("ssnd.in", "r", stdin);
freopen ("ssnd.out", "w", stdout);

sieve ();

int tests;
scanf ("%d", &tests);
while (tests--) {
ll n;

scanf ("%lld", &n);
ll nd = 1, sd = 1;
for(int i = 0; i < K && 1LL * primes[i] * primes[i] <= n; ++i) {
if(n % primes[i]) continue;

int p = 0;
while(n % primes[i] == 0) {
n /= primes[i];
++p;
}
nd *= (p + 1);

nd %= MOD;
ll pp = (factor(primes[i], p + 1) + MOD) % MOD;

sd = (sd * pp) % MOD;
}
if(n > 1) {
nd *= 2;
sd = (1LL*sd*(n+1) % MOD);
}
nd = (nd + MOD) % MOD;
sd = (sd + MOD) % MOD;

printf ("%lld %lld\n", nd, sd);
}

return 0;
}
``````