Cod sursa(job #2141724)

Utilizator DanielznaceniDaniel Danielznaceni Data 24 februarie 2018 15:54:13
Problema Suma si numarul divizorilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <bitset>
#define lim 1000005
#define modul 9973
using namespace std;

bitset <lim> nope;
ifstream in("ssnd.in");
ofstream out("ssnd.out");

int t, k, i, j, x;
long long n, prime[lim];

void ciur()
{
    for(i=2; i<=lim; ++i)
    {
        if(nope[i]==0)
        {
            prime[++k]=i;
            for(j=i+i; j<=lim; j=j+i)
            {
                nope[j]=1;
            }
        }
    }
}

int rezolvarea(int x)
{
    long long nf, nd=1, sd=1, cop;
    for(i=1; i<=k && x>1 && prime[i]*prime[i]<=x; ++i)
    {
        if(x%prime[i]==0)
        {
            nf=0;
            while(x%prime[i]==0)
            {
                x/=prime[i];
                ++nf;
            }
            nd=nd*(nf+1);
            cop=prime[i];
            while(nf>0)
            {
                cop*=prime[i];
                --nf;
            }
            --cop;
            sd=sd*((cop)/(prime[i]-1))%modul;
        }
    }
    if(x>1)
    {
        nd*=2;
        sd=sd*(x+1);
        sd=sd%modul;
    }
    sd=sd%modul;
    out<<nd<<" "<<sd<<"\n";
}

int main()
{
    int t, k=0, i, j, x;
    ciur();
    in>>t;
    for(i=1; i<=t; ++i)
    {
        in>>x;
        rezolvarea(x);
    }
    return 0;
}