Cod sursa(job #1928274)

Utilizator tziplea_stefanTiplea Stefan tziplea_stefan Data 15 martie 2017 23:55:24
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.36 kb
#include <fstream>
#include <cmath>
#include <bitset>
#define MOD 9973
#define VAL 1000005

using namespace std;

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

int T, cnt, k, e;
int v[VAL], K;
long long N, j;
int NRDIV, SUM, i;
bitset<VAL> ok;

int putere(int nr, int e)
{
    int P=1;
    while (e!=0)
    {
        if (e % 2==1)
        {
            P*=nr;
            P%=MOD;
            e--;
        }
        e/=2;
        nr*=nr;
        nr%=MOD;
    }
    return P;
}

void Sieve()
{
    ok[1]=ok[0]=1;
    for (i=2; i<=VAL; i++)
    {
        if (ok[i]==0)
        {
            v[++K]=i;
            for (j=1LL*i*i; j<=VAL; j+=i)
              ok[i]=1;
        }
    }
}

int main()
{
    fin >> T;
    Sieve();
    for (cnt=1; cnt<=T; cnt++)
    {
        fin >> N;
        SUM=1;
        NRDIV=1;
        for (k=1; 1LL*v[k]*v[k]<=N; k++)
        {
            e=0;
            while (N % v[k]==0)
            {
                N/=v[k];
                e++;
            }
            NRDIV*=(e+1);
            int P1=(putere(v[k], e+1)-1) % MOD;
            int P2=putere(v[k]-1, MOD-2) % MOD;
            SUM=(((SUM*P1) % MOD)*P2) % MOD;
        }
        if (N!=1)
        {
            N%=MOD;
            NRDIV*=2;
            SUM=(1LL*SUM*(N+1)) % MOD;
        }
        fout << NRDIV << " " << SUM << '\n';
    }
    fin.close();
    fout.close();
    return 0;
}