Cod sursa(job #2384639)

Utilizator Andy_ANDYSlatinaru Andrei Alexandru Andy_ANDY Data 20 martie 2019 23:03:47
Problema Suma divizorilor Scor 30
Compilator cpp-64 Status done
Runda excelenta-tema2 Marime 1.23 kb
#include <bits/stdc++.h>
using namespace std;
int baze[50],puteri[50],cnt=0;
long long a,b,sol=1;
void invmod(int &x,int &y,int a,int b)
{   if (!b)  x = 1, y = 0;
    else
    {   invmod(x, y, b, a % b);
        int aux = x;
        x = y;
        y = aux - y * (a / b);
     }
}
long long Rlog2(int b,int p)
{   long long r=1;
    while(p)
    {   if(p&1) r*=b;
        b*=b;
        p>>=1;
    }
    return r;
}
void afis()
{   ofstream g ( "sumdiv.out" );
    g<<sol;
}
void citire()
{   ifstream f ( "sumdiv.in" );
    f>>a>>b;
}
void desc(int n)
{   for(int d=2;d*d<=n;d++)
    {   if(n%d==0)
        {   int e=0;
            while(n%d==0)
            {   n/=d;
                e++;
            }
            cnt++;
            baze[cnt]=d; puteri[cnt]=e;
        }
    }
    if(n>1) baze[++cnt]=n,puteri[cnt]=1;
}
void rezolva()
{   for(int i=1;i<=cnt;i++)
    {   int w=Rlog2(baze[i],(puteri[i]*b+1));
        w--;
        sol=sol*w%9901;
    }
    for(int i=1;i<=cnt;i++)
    {   int cx,cy,a,b;
        invmod(cx,cy,( baze[i]-1),9901);
        if(cx<=0) cx=9901+cx%9901;
        sol=sol*cx%9901;
    }
}
int main()
{   citire();
    desc(a);
    rezolva();
    afis();
    return 0;
}