Cod sursa(job #2184310)

Utilizator MarianConstantinMarian Constantin MarianConstantin Data 23 martie 2018 22:09:45
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <iostream>
#include <fstream>
#define M 9973

using namespace std;

void euclid(long long a, long long b, long long &x, long long &y)
{
    if (!b)
    {
        x=1;
        y=0;
        return;
    }
    euclid(b, a%b, x, y);
    long long aux;
    aux=y;
    y=x-(a/b)*y;
    x=aux;
}

int main()
{
    ifstream fin("ssnd.in");
    ofstream fout("ssnd.out");
    long long n, s, p, pr, x, y;
    int t, d, nr;
    fin >> t;
    for (int i=1; i<=t; i++)
    {
        fin >> n;
        d=2;
        s=1;
        p=1;
        while(n>1)
        {
            nr=0;
            pr=1;
            while(n%d==0)
                nr++,n/=d,pr*=d;
            pr*=d;
            pr--;
            if (nr)
            {
                s=s*(nr+1);
                p=((p%M)*(pr%M))%M;
                euclid(d-1, M, x, y);
                while(x<0)
                    x+=M;
                p=((p%M)*(x%M))%M;
            }
            d++;
        }
        fout << s << " " << p << "\n";
    }
    return 0;
}