Cod sursa(job #2979837)

Utilizator nici40Nikita Moglan nici40 Data 15 februarie 2023 23:02:55
Problema Suma si numarul divizorilor Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.38 kb
#include <bits/stdc++.h>
using namespace std;
struct fact
{
    long long factor, power;
};
int main()
{
    ifstream fin;
    fin.open("ssnd.in");
    ofstream fout;
    fout.open("ssnd.out");
    vector<fact> f_p;
    long long n = 1000000;
    short int arr[n+5];
    for(int i = 1; i <= n; i++)
    {
        arr[i] = 0;
    }
    arr[0] = 1;
    arr[1] = 1;
    for(long long i = 2; i < n/2; i++)
    {
        if(arr[i] == 0)
        {
            long long current = i*2;
            while(current <= n)
            {
                arr[current] = 1;
                current+=i;
            }
        }
    }
    int t  = 0;
    fin >> t;
    for(int q = 0; q < t; q++)
    {
        long long n = 0;
        fin >> n;
        int val = 2;
        f_p.clear();
        vector<long long> factorisation;
        while(n != 1)
        {
            if(arr[val] == 0)
            {
                if(n % val == 0)
                {
                    factorisation.push_back(val);
                    n/=val;
                }
                else
                {
                    val++;
                }
            }
            else
            {
                val++;
            }
        }
        //for(int i = 0; i < factorisation.size(); i++)
            //cout << factorisation[i] << ' ';
        factorisation.push_back(1);
        int len = factorisation.size();
        int pos = 0;
        int powerr = 1;
        for(int i = 0; i < len-1; i++)
        {
            if(factorisation[i] == factorisation[i+1])
            {
                powerr++;
            }
            else
            {
                struct fact abc;
                abc.power = powerr;
                abc.factor = factorisation[i];
                f_p.push_back(abc);
                pos++;
                powerr = 1;
            }
        }
        long long n_div = 1;
        long long suma = 1;
        for(int i = 0; i < pos; i++)
        {
            //cout << f_p[i].power << ' ';
            n_div *= f_p[i].power + 1;
            suma *= (pow(f_p[i].factor, f_p[i].power + 1)-1) / (f_p[i].factor - 1);
            suma = suma % 9973;
            //cout << f_p[i].factor << ' ' << f_p[i].power+1 << ' ' << pow(f_p[i].factor, f_p[i].power + 1) << '\n';
        }
        fout << n_div << ' ' << suma << '\n';

    }//518
}