Mai intai trebuie sa te autentifici.

Cod sursa(job #2155339)

Utilizator Alex18maiAlex Enache Alex18mai Data 7 martie 2018 20:03:35
Problema Suma divizorilor Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.63 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream cin ("sumdiv.in");
ofstream cout ("sumdiv.out");

const long long MAX = 10000LL;

bool ciur [MAX + 5];
vector <long long> prim;

void Ciur(){

    for (long long i=2; i<=MAX; i++){
        if (!ciur[i]){
            prim.push_back(i);
            for (long long j=i+i; j<=MAX; j+=i){
                ciur[j] = true;
            }
        }
    }
}

vector <pair<long long , long long>> DIV;

const long long MOD = 9901LL;

long long rid (long long base , long long put){

    long long ans = 1LL;

    while (put){

        if (put % 2LL){
            ans *= base;
            ans %= MOD;
        }
        base *= base;
        base %= MOD;
        put /= 2LL;
    }

    return ans;

}

int main() {

    long long a , b;
    cin>>a>>b;

    Ciur();

    long long cop = a;

    for (auto &x : prim){
        if (x * x > a){
            break;
        }
        long long cont = 0;
        while (!(cop % x)){
            cop /= x;
            cont++;
        }
        if (!(x % MOD)){
           continue;
        }
        if (cont){
            DIV.push_back({x , cont*b});
        }
    }

    if (cop > 1LL){
        DIV.push_back({cop , b});
    }

    long long sus = 1LL;
    long long jos = 1LL;

    for (auto &x : DIV){

        if (!((x.first - 1LL) % MOD)){
            sus *= x.second + 1LL;
            continue;
        }

        long long ridicat = rid(x.first , x.second + 1LL);
        sus *= ridicat - 1LL;
        sus %= MOD;
        jos *= x.first - 1LL;
        jos %= MOD;
    }

    jos = rid(jos , MOD-2LL);
    sus *= jos;
    sus %= MOD;

    cout<<sus;

    return 0;
}