Cod sursa(job #3282790)

Utilizator David2007David Preda David2007 Data 6 martie 2025 20:26:06
Problema Suma si numarul divizorilor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.41 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("ssnd.in");
ofstream g("ssnd.out");

long long int n,x,nrd,sd;
bitset <1000001> ciur;
vector <long long int> prime;

void ciurul()
{
    ciur[0]=1;
    ciur[1]=1;
    for(int i=2; i<=1000001; i++)
        if(ciur[i]==0)
        {
            prime.emplace_back(i);
            for(int j=i; 1ll*j*i<=1000001; j++)
                ciur[i*j]=1;
        }
}

long long int put(int a,int n)
{
    int p=1;
    a=a%9973;
    while(n)
    {
        if(n%2==1)
            {p=p*a;
            p=p%9973;
            }
        a=a*a;
        a=a%9973;
        n/=2;
    }
    return p;
}

int invers(int n)
{
    return put(n,9971);
}
int main()
{
    ciurul();
    f>>n;
    for(; n>0; n--)
    {
        f>>x;
        nrd=1;
        sd=1;
        long long int p,d=2,pos=0;
        while(prime[pos]*prime[pos]<=x && pos<prime.size())
        {
            p=0;
            while(x%prime[pos]==0)
            {
                p++;
                x=x/prime[pos];
            }
            nrd*=(p+1);
            if(p>0)
            {
                sd=sd*(put(prime[pos],p+1)-1)%9973*invers(prime[pos]-1)%9973;
            }
            pos++;

        }
         if(x!=1)
            {
                nrd=nrd*2;
                sd=(1ll*(x+1)*sd)%9973;
            }
        g<<nrd<<" "<<sd%9973<<"\n";
    }

}