Cod sursa(job #2069999)

Utilizator danny794Dan Danaila danny794 Data 19 noiembrie 2017 04:44:05
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.38 kb
#include <bitset>
#include <cstdint>
#include <fstream>
#include <vector>

#define PMAX 1005
#define NMAX 80000
#define MOD 9973

std::ifstream cin("ssnd.in");
std::ofstream cout("ssnd.out");
std::bitset<PMAX * PMAX> isPrime;
int64_t primes[NMAX];
int64_t noPrimes;

void findPrimes() {
  /* Mark all numbers as prime. */
  isPrime.set();
  primes[0] = 2;
  noPrimes = 1;
  for (int64_t i = 3; i < PMAX; i += 2) {
    if (isPrime[i]) {
      for (int64_t j = i * i; j < isPrime.size(); j += 2 * i) {
        isPrime[j] = false;
      }
    }
  }
  for (size_t i = 3; i < PMAX * PMAX; i += 2) {
    if (isPrime[i]) {
      primes[noPrimes++] = i;
    }
  }
}

void solve(int64_t n) {
  int64_t currentSum = 1;
  int64_t noDivisors = 1;
  int64_t power = 0;
  int64_t aux = 0;
  size_t idx = 0;
  while (n > 1 && idx < noPrimes) {
    int64_t p = primes[idx];
    if (n % p == 0) {
      power = 0;
      aux = 1;
      while (n % p == 0) {
        n /= p;
        power++;
        aux *= p;
      }
      noDivisors *= (1 + power);
      currentSum = currentSum * ((aux * p - 1) / (p - 1)) % MOD;
    }
    idx++;
  }
  if (n > 1) {
    /* n is prime */
    noDivisors *= 2;
    currentSum = currentSum * (n + 1) % MOD;
  }
  cout << noDivisors << " " << currentSum << "\n";
}

int main() {
  int64_t n, tests;
  findPrimes();
  cin >> tests;
  while (tests--) {
    cin >> n;
    solve(n);
  }
  return 0;
}