Cod sursa(job #2931069)

Utilizator Teodor94Teodor Plop Teodor94 Data 30 octombrie 2022 14:09:24
Problema Suma divizorilor Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 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;

}

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;
       if(p%Mod!=1){
       x=putere(p-1, Mod-2);

          nr=putere(p, e+1)%Mod-1;
          nr+=Mod;
          nr%=Mod;
          s*=((long long)x*nr)%Mod;
       }
       else
          s*=(e+1)%Mod;
          s%=Mod;
        }
        ++p;
    }
    if(a>1){
        if(a%Mod!=1){
        x=putere(a-1, Mod-2);
          nr=putere(a, b+1)%Mod-1;
          nr+=Mod;
          nr%=Mod;
          s*=((long long)x*nr)%Mod;
        }
        else s*=(b+1);
          s%=Mod;
    }
    out<<s;
    return 0;
}