Cod sursa(job #2580967)

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

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;
}

int main(){
  //  ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
  //  srand(chrono::steady_clock::now().time_since_epoch().count());
    ifstream fin("ssnd.in");
    ofstream fout("ssnd.out");
    for(int i=2;i<=nmax;i++){
        if(viz[i]==0){
            divi.push_back(i);
            for(int j=2*i;j<=nmax;j+=i) viz[j]=1;
        }
    }
    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);
            if(x<0LL) x+=m;
            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);
            if(x<0LL) x+=m;
            sum=(sum*x)%m;
            x=lgp(n-1LL,m-2LL);
            sum=(sum*x)%m;
        }
        fout << nrdiv << ' ' << sum << '\n';
    }
}