Cod sursa(job #2565909)

Utilizator AndreiDeltaBalanici Andrei Daniel AndreiDelta Data 2 martie 2020 17:47:41
Problema Suma si numarul divizorilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.39 kb
#include <bits/stdc++.h>
#define Mod 9973
using namespace std;
ifstream f("ssnd.in");
ofstream g("ssnd.out");
typedef long long ll;
int T,y;

vector < pair< ll , ll > > Div[1001];

void Euclid(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return;
    }
    ll x0,y0;
    Euclid(b,a%b,x0,y0);
    x=y0;
    y=x0-(a/b)*y0;
}

ll IM(ll X)
{
    X%=Mod;

    ll x,y;
    Euclid(X,Mod,x,y);

    if( x < 0 ) x+=Mod;

    return x;
}

ll Exp(ll a,ll b)
{
    ll ans=1;
    int lg=log2(b)+1;
    for(int i=lg;i>=0;i--)
    {
        ans=ans*ans;
        if( ( b & ( 1 << i ) ) > 0 ) ans*=a;
    }
    return ans;
}

int main()
{
    f>>T;
    for(int t=1;t<=T;t++)
    {
        f>>y;
        for(int i=2;i*i<=y;i++)
        if( y % i == 0 )
        {
            ll cnt=0;
            while( y % i == 0 )
            {
                y/=i;
                cnt++;
            }
            Div[t].push_back({i,cnt});
        }
        if( y != 1 ) Div[t].push_back({y,1});

        ll ans1=1,ans2=1;

        for(int i=0;i<Div[t].size();i++)
        {
            ll p=Div[t][i].first,alpha=Div[t][i].second;
            ll ras=Exp(p,alpha+1);

            ans1=ans1*(alpha+1);
            ans2=( ( ( ( ras - 1 )%Mod ) * IM(p-1) ) % Mod * ans2 ) % Mod;
        }
        g<<ans1<<' '<<ans2<<'\n';
    }


    return 0;
}