Cod sursa(job #1714144)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 7 iunie 2016 17:18:09
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.79 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 ], pp[ pmax + 1 ];

bool ciur[ nmax / 2 + 1 ];

int lgput( int b, int e ) {
    long long sol = 1;
    b %= mod;
    while ( e > 0 ) {
        if ( e & 1 ) {
            sol = (sol * b) % mod;
        }
        b = (b * b) % mod;
        e >>= 1;
    }
    return sol % mod;
}
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;

    for( int i = 0; i < nrp; ++ i ) {
        pp[ i ] = lgput( p[ i ] - 1, mod - 2 );
    }
}
int main() {
    int t, suma, nrdiv, e; long long n, aux;
    ciurulet();

    fin >> t;

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

        suma = 1;
        aux = n;
        nrdiv = 1, e = 0;

        for( int i = 0; 1LL * p[ i ] * p[ i ] <= aux; ++ i ) {
            if ( aux % p[ i ] == 0 ) {
                e = 0;
                while ( aux % p[ i ] == 0 ) {
                    ++ e;
                    aux /= p[ i ];
                }

                nrdiv *= (e + 1);
                suma *= ( (lgput( p[ i ], e + 1 ) - 1) * pp[ i ] ) % mod;
                suma %= mod;
            }
        }

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

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