Cod sursa(job #2379193)

Utilizator sansRotaru Razvan Andrei sans Data 13 martie 2019 07:58:59
Problema Suma si numarul divizorilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.48 kb
#include <bits/stdc++.h>
using namespace std;
#define M 1000000
#define MOD 9973
int prime[M+5], k;
bitset <M>ciuruit;
typedef long long ll;
ll fast_exp(ll base, ll exp){
    if(!exp) return 1;
    if(exp==1) return base;
    if(exp%2) return base * fast_exp(base, exp-1);
    else return fast_exp(base*base, exp/2);
}
void ciur(){
    for(int i = 2; i<=1000; i++){
        if(!ciuruit[i]){
            for(int j = 2; j<=M/i; j++) ciuruit[i*j] = 1;
        }
    }
    prime[k++] = 2;
    for(int i = 3; i<=M; i+=2)
        if(!ciuruit[i]) prime[k++] = i;
}
ll getsumanddivs(ll x, ll &sum){
    sum = 1;
    int p = 1, d = 0, e = 0;
    ll f = prime[d++];

    while(x%f==0){
        e++;
        x/=f;
    }
    if(e>0){
        p*=(e+1)%MOD;
        sum*=(fast_exp(f, e+1)-1)/(f-1) % MOD;
    }

    f = prime[d++];

    while(f*f<=x){
        e = 0;
        while(x%f==0){
            e++;
            x/=f;
        }
        if(e>0){
            p*=(e+1)%MOD;
            sum*=(fast_exp(f, e+1)-1)/(f-1)%MOD;
        }
        f = prime[d++];
    }

    if(x>1){
        p*=2%MOD;
        sum*=((fast_exp(x, 2)-1)/(x-1))%MOD;
    }
    return p;
}
int main(){
    freopen("ssnd.in", "r", stdin);
    freopen("ssnd.out", "w", stdout);
    ciur();
    int n;
    ll x, sum;
    scanf("%d", &n);
    for(int i = 1; i<=n; i++){
        scanf("%lld", &x);
        ll h  = getsumanddivs(x, sum);
        printf("%lld %lld\n", h, sum);
    }
}