Cod sursa(job #2930791)

Utilizator anastasiadumitru3Dumitru Anastasia anastasiadumitru3 Data 29 octombrie 2022 16:34:46
Problema Suma divizorilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <fstream>

using namespace std;
# define Mod 9901
int putere(int a, int n){
    if(n%2==0)
        return((long long )( putere(a,n/2)% Mod)*(putere(a,n/2)% Mod))%Mod;
    else if(n%2==1 && n!=1)
        return (((long long )(putere(a,n/2)%Mod)*(putere(a,n/2)%Mod))%Mod*(a%Mod))%Mod;
    else return a%Mod;

}
void euclid(int a, int b, int &d, int &x, int &y){
    if (b == 0){
        d = a;
        x = 1;
        y = 0;
    }
    else{
        int x0, y0;
        euclid(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}
int main()
{
    ifstream in("sumdiv.in");
    ofstream out("sumdiv.out");
    int n, a, i, b, p, d, x, y;
    long long s=1, e, nr;
    in>>a>>b;
    p=2;
    while(p*p<=a)
    {
        e=0;
        if(a%p==0){
        while (a%p==0)
        {
            a=a/p;
            ++e;
        }

       e*=b;
        euclid(p-1, Mod, d, x, y);
         while(x<0)
            x+=Mod;
          nr=putere(p, e+1)%Mod-1;
          s*=((long long)x*nr)%Mod;
        }
        ++p;
    }

    if (a > 1){

       euclid(a-1, Mod, d, x, y);
        while(x<0)
            x+=Mod;
            nr=putere(a, b+1)%Mod-1;
          s*=((long long)x*nr)%Mod;
    }
    out<<s;
    return 0;
}