Cod sursa(job #3237698)

Utilizator tsg38Tsg Tsg tsg38 Data 11 iulie 2024 21:28:16
Problema Suma si numarul divizorilor Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

const int DIM = 1e6 + 1;

bool ciur[DIM];
int pr[DIM];

int main() {
  ios_base::sync_with_stdio(0);
  fin.tie(0);
  int t, idx = 0;
  ll n;

  fin >> t;
  for ( int d = 2; d * d < DIM; ++d ) {
	if ( !ciur[d] ) {
	  pr[++idx] = d;
	  for ( int i = d * d; i < DIM; i += d ) {
		ciur[i] = 1;
	  }
	}
  }
  pr[++idx] = DIM;
  while ( t-- ) {
	fin >> n;
    int i = 1;
	ll s = 1, d = 1;
	while ( pr[i] * pr[i] <= n ) {
      int e = 0;
	  ll p = 1;
	  while ( n % pr[i] == 0 ) {
		n /= pr[i];
		p *= pr[i];
	    ++e;
	  }
	  d *= (e + 1);
      s *= (p * pr[i] - 1) / (pr[i] - 1);
	  ++i;
	}
	if ( n > 1 ) {
	  d *= 2;
	  s *= (n + 1);
	}
	fout << d << " " << s << "\n";
  }
  fin.close();
  fout.close();
  return 0;
}