Cod sursa(job #2458240)

Utilizator sabinandreiBocan Sabin Andrei sabinandrei Data 19 septembrie 2019 22:44:13
Problema Suma si numarul divizorilor Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.34 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(long long a, long long b)
{
    long long p=1;
    while (b)
    {
        if (b%2==1) p=p*a;
        b/=2;
        a=a*a;
    }
    return p;
}

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(p[j]*p[j]<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';
    }
}