Cod sursa(job #2580979)

Utilizator bigmixerVictor Purice bigmixer Data 14 martie 2020 13:39:11
Problema Suma si numarul divizorilor Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.25 kb
#include <bits/stdc++.h>
using namespace std;

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

const int m=9973;

const int nmax=1000005;

int t;
long long n;
bitset<nmax>viz;
vector<int>divi;

long long lgp(int a,int b){
    long long res=1LL,pop=a;
    for(int i=0;(1<<i)<=b;i++){
        if(b&(1<<i)) res=(res*pop)%m;
        pop=(pop*pop)%m;
    }
    return res;
}

void ciur(){
    for(int i=2;i<nmax;i++){
        if(viz[i]==0){
            divi.push_back(i);
            for(int j=i+i;j<nmax;j+=i) viz[j]=1;
        }
    }
}

int main(){
    ciur();
    fin >> t;
    while(t--){
        fin >> n;
        long long nrdiv=1LL,sum=1LL;
        for(auto i:divi){
            if(n%i==0){
            int cnt=0;
            while(n%i==0){
                cnt++;
                n/=i;
            }
            nrdiv*=(cnt+1LL);
            nrdiv=(nrdiv)%m;
           if(cnt){ long long x=(lgp(i,cnt+1LL)-1LL);
            sum=(sum*x)%m;
            x=lgp(i-1LL,m-2LL);
            sum=(sum*x)%m; } }
        }
        if(n>=2LL) nrdiv=(nrdiv*2LL)%m;
        if(n>=2){
            long long x=(lgp(n,2LL)-1LL);
            sum=(sum*(n+1LL))%m;
        }
        fout << nrdiv << ' ' << sum << '\n';
    }
}