Cod sursa(job #2587096)

Utilizator sulzandreiandrei sulzandrei Data 22 martie 2020 00:03:40
Problema Suma si numarul divizorilor Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.28 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <utility>
#include <cstring>
#include <bitset>
#include <vector>
using namespace std;

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

#define ull unsigned long long int
#define mod 9973
struct Pair{
    public:
        ull p,r;
    Pair(ull a, ull b){
        this->p=a;
        this->r = b;
    }
};


ull exp(ull a, ull n){
    ull res=1;

    while(n){
        if(n&1)
            res = ((res%mod)*(a%mod))%mod;
        a = ((a%mod)*(a%mod))%mod;
        n >>=1;
    }
    return res;
}

vector<Pair> work(ull n){

    vector<Pair> pairs;

    for(ull i = 2; i*i <=n ; i++){
        if(n%i ==0 ) {
            ull nr=0;
            while(n%i==0){
                nr++;
                n /=i;
            }
            pairs.push_back(Pair(i,nr));
        }
    }
    if(n >1) pairs.push_back(Pair(n,1));
    return pairs;
}


int main ( )
{
    ull n,t;
    in>>t;
    while(t--){
        in>>n;
        vector<Pair> pairs = work(n);
        ull d=1,s=1;
        for(vector<Pair>::iterator it = pairs.begin(); it != pairs.end() ;it++){
            d = ((d%mod)*(it->r+1))%mod;
            ull pow = ((exp(it->p, it->r+1)-1)/(it->p-1))%mod;
            s = (s*pow)%mod;
        }
        out<<d<<" "<<s<<'\n';
    }

    return 0;
}