Cod sursa(job #2458239)

Utilizator sabinandreiBocan Sabin Andrei sabinandrei Data 19 septembrie 2019 22:40:18
Problema Suma si numarul divizorilor Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.42 kb
//
//  main.cpp
//  ssnd
//
//  Created by Sabin Andrei on 9/15/19.
//  Copyright © 2019 Sabin Andrei. All rights reserved.
//

#include <fstream>
#include <iostream>
#include <cmath>

using namespace std;

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


long long cck(int b, int e)
{
    long long r = 1;
    b %= 9973;
    while(e)
    {
        if(e & 1)
        {
            r *= b;
            r %= 9973;
        }
        b *= b;
        b %= 9973;
        e >>= 1;
    }
    return r;
}

bool ciur[1000009];
unsigned long long n,i,j,m,p[1000009],d,x,nd=1,sd=1,pl;

int main()
{
    in>>n;
    for(d=2;d*d<=1000000;d++)
    {
        if(ciur[i]==0)
        {
            for(j=d*d;j<=1000000;j+=d)
            {
                ciur[i]=1;
            }
        }
    }
    int pp=0;
    for(i=2;i<=1000000;i++)
    {
        if(ciur[i]==0)
        {
            pp++;
            p[pp]=i;
        }
    }
    for(i=1;i<=n;i++)
    {
        in>>x;
        j=1;
        pl=0;
        nd=1;
        sd=1;
        unsigned long long y=p[j];
        while(y<=sqrt(x))
        {
            y=p[j];
            pl=1;
            while(x%y==0)
            {
                x=x/y;
                pl++;
            }
            nd*=pl;
            sd=(sd*((cck(y,pl)-1)/(y-1)))%9973;
            j++;
        }
        if (x!=1)
        {
            nd*=2;
            sd=(sd*(x*x-1)/(x-1))%9973;
        }
        out<<nd<<" "<<sd<<'\n';
    }
}