Cod sursa(job #1714120)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 7 iunie 2016 15:18:00
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.44 kb
#include<fstream>
#include<bitset>
#include<cmath>

using namespace std;

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

const int nmax = 1e6;
const int pmax = 78499;
const int mod = 9973;

int nrp;
int p[ pmax + 1 ];

bitset< nmax / 2 + 1 > ciur;

void ciurulet() {
    for( int i = 3; i * i <= nmax; i += 2 ) {
        if ( ciur[ i >> 1 ] == 0 ) {
            for( int j = i * i; j <= nmax; j += (i << 1) ) {
                ciur[ j >> 1 ] = 1;
            }
        }
    }
    nrp = 0;
    p[ nrp ++ ] = 2;
    for( int i = 3; i <= nmax; i += 2 ) {
        if ( ciur[ i >> 1 ] == 0 ) {
            p[ nrp ++ ] = i;
        }
    }
    p[ nrp ++ ] = nmax + 5;
}
int main() {
    int t; long long n;
    ciurulet();

    fin >> t;

    while ( t -- ) {
        fin >> n;

        int suma = 1, lim = sqrt( n );
        long long aux = n;
        long long nrdiv = 1;

        for( int i = 0; p[ i ] <= lim; ++ i ) {
            int b = p[ i ], e = 0;
            long long pp = 1;
            while ( aux % b == 0 ) {
                ++ e;
                aux /= b;
                pp *= b;
            }

            nrdiv *= (e + 1);
            suma *= ( (pp * b - 1) / (b - 1) ) % mod;
            suma %= mod;
        }

        if ( aux > 1 ) {
            nrdiv *= 2;
            suma = suma * ((aux * aux - 1) / (aux - 1) % mod) % mod;
        }

        fout << nrdiv << " " << suma << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}