Cod sursa(job #2070001)

Utilizator danny794Dan Danaila danny794 Data 19 noiembrie 2017 04:57:25
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.33 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];
int noPrimes;

void findPrimes() {
  /* Mark all numbers as prime. */
  isPrime.set();
  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;
      }
    }
  }
  primes[0] = 2;
  noPrimes = 1;
  for (size_t i = 3; i < isPrime.size(); i += 2) {
    if (isPrime[i]) {
      primes[noPrimes++] = i;
    }
  }
}

void solve(int64_t n) {
  int64_t currentSum = 1, noDivisors = 1, power = 0, aux = 0;
  for (int i = 0; i < noPrimes && n >= primes[i] * primes[i]; i++) {
    if (n % primes[i]) {
      continue;
    }
    power = 0;
    aux = 1;
    while (n % primes[i] == 0) {
      n /= primes[i];
      power++;
      aux = aux * primes[i] + 1;
    }
    noDivisors *= (1 + power);
    currentSum = currentSum * aux % MOD;
  }
  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;
}