Cod sursa(job #3215360)

Utilizator YuzukyIstrate Andreea Ruxandra Yuzuky Data 14 martie 2024 20:50:11
Problema Suma si numarul divizorilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.27 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("ssnd.in");
ofstream out("ssnd.out");
const int MAX = 1000000;
char ciur[MAX+1];
vector<int> v; //vector in care pun nr prime
int main()
{
    int t,n;
    in>>t;
    ciur[0]=ciur[1]=1;
    for(int i=2; i*i<=MAX; ++i)
    {
        if(ciur[i]==0)
        {
            for(int d=i*i; d<=MAX; d=d+i)
                ciur[d]=1;
        }
    }
    for(int i=2; i<=MAX; ++i)
        if(ciur[i]==0)
            v.push_back(i);

    for(int test=0; test<t; ++test)
    {
        in>>n;
        int i=0, nrdiv=1;
        long long s=1;
        while(v[i]*v[i]<=n && i<v.size())
        {
            if(n%v[i]==0)
            {
                int exp=0;
                long long power=v[i];
                while(n%v[i]==0)
                {
                    ++exp;
                    power=power*v[i];
                    n/=v[i];
                }
                nrdiv*=(exp+1);
                s=s*(power-1)/(v[i]-1);
                s=s%9973;
            }
            ++i;
        }
        if(n>1)
        {
            nrdiv*=2;
            s*=(n*n-1)/(n-1);
            s=s%9973;
        }
        out<<nrdiv<<" "<<s<<'\n';
    }
    return 0;
}