Cod sursa(job #1928311)

Utilizator tziplea_stefanTiplea Stefan tziplea_stefan Data 16 martie 2017 00:25:50
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.75 kb
#include <fstream>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <vector>
#define MOD 9973
#define VAL 1000005

using namespace std;

vector<int> v;
bitset<VAL> ok;

int poz=0;
char buff[MOD];

long long citeste()
{
    long long nr=0;
    while (buff[poz]<'0' || buff[poz]>'9')
      if (++poz==MOD)
        fread(buff, 1, MOD, stdin), poz=0;
    while (buff[poz]>='0' && buff[poz]<='9')
    {
        nr=nr*10+buff[poz]-'0';
        if (++poz==MOD)
          fread(buff, 1, MOD, stdin), poz=0;
    }
    return nr;
}

int putere(int nr, int e)
{
    int P=1;
    nr%=MOD;
    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 (int i=2; i<VAL; i++)
    {
        if (ok[i]==0)
        {
            v.push_back(i);
            for (int j=i+i; j<VAL; j+=i)
              ok[i]=1;
        }
    }
}

void Get_ANS()
{
    long long N;
    int SUM=1, NRDIV=1;
    N=citeste();
    for (int k=0; 1LL*v[k]*v[k]<=N; k++)
    {
        if (N % v[k]==0)
        {
            int 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)
    {
        NRDIV*=2;
        SUM=(1LL*SUM*(N+1)) % MOD;
    }
    printf("%d %d\n", NRDIV, SUM);
}

int main()
{
    freopen("ssnd.in", "r", stdin);
    freopen("ssnd.out", "w", stdout);
    long long T;
    Sieve();
    T=citeste();
    while (T!=0)
    {
        Get_ANS();
        T--;
    }
    return 0;
}