Cod sursa(job #2494982)

Utilizator AlexPascu007Pascu Ionut Alexandru AlexPascu007 Data 18 noiembrie 2019 18:57:06
Problema Suma si numarul divizorilor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.54 kb
#include <bits/stdc++.h>
#define DIM 1000010
#define mod 9973
using namespace std;
ifstream fin("ssnd.in");
ofstream fout("ssnd.out");
bitset<DIM> v;
long long n, m;
int t,i,j,sdiv,nrdiv,x,y,p,P[DIM],d,e;
int putere(int a, int b) {
	if (b==0)
		return 1;
	if (b==1)
		return a%mod;
	else {
		int c=putere(a,b/2);
		c=c*c;
		if (b%2==0)
			return c%mod;
		else
			return ((a%mod)*(c%mod))%mod;
	}
}
int main() {
    P[p=1]=2;
    for (i=3;i<=1000000;i+=2) {
        if (!v[i]) {
            P[++p] = i;
            for (j=i+i;j<=1000000;j+=i)
                v[j] = 1;
        }
    }
    fin>>t;
    while (t--) {
        fin>>n;
        int m=sqrt(n);
        nrdiv=1, sdiv=1;
        for (i=1;n!=1&&1LL*P[i]*P[i]<=n;i++) {
            if (n%P[i]==0) {
                d=P[i];
                e=1;
                while (n%d==0) {
                    e++;
                    n/=d;
                }
                nrdiv*=e;
                x=putere(d,e);
                x--;
                if (x<0)
                    x+=mod;
                y=putere((d+mod-1)%mod,mod-2);
                x=x*y%mod;
                sdiv=sdiv*x%mod;
            }
        }
        if (n!=1) {
            d=n%mod;
            e=2;
            nrdiv=nrdiv*e;
            x=putere(d,e);
            x--;
            if (x<0)
                x+=mod;
            y=putere((d+mod-1)%mod,mod-2);
            x=x*y%mod;
            sdiv=sdiv*x%mod;
        }
        fout<<nrdiv<<" "<<sdiv<<"\n";
    }
    return 0;
}