Cod sursa(job #2106304)

Utilizator MotoAMotoi Alexandru MotoA Data 15 ianuarie 2018 16:25:22
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.57 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssnd.in");
ofstream g("ssnd.out");
const int MOD = 9973;
int v[1000001], prim;

void ciur(int n)
{
    for(int i = 4; i <= n; i += 2)
        v[i] = 1;
    for(int i = 3; i * i <= n; i += 2)
        if(!v[i])
        {
            for(int j = i * i; j <= n; j += i)
                v[j] = 1;
        }
    v[++prim] = 2;
    for(int i = 3; i <= n; i += 2)
        if(!v[i])v[++prim] = i;
}

int pow(int a, int b)
{
    if(!b)return 1;
    if(b == 1)return a % MOD;
    if(b % 2 == 0)return pow(1LL * a * a % MOD, b / 2) % MOD;
    return 1LL * a * pow(1LL * a * a % MOD, b / 2) % MOD;
}

int invers_mod(int a)
{
    return pow(a, MOD - 2);
}

void suma_numar_div(long long n, int &s, int &nr)
{
    long long p = 0;
    s = nr = 1;
    for(int i = 1; i <= prim && v[i]*v[i] <= n ; i++)
        if(n % v[i] == 0)
        {
            p = 0;
            while(n % v[i] == 0)
            {
                p++;
                n /= v[i];
            }
            nr *= 1LL * (p + 1) % MOD;
            nr %= MOD;
            s *= 1LL * (pow(v[i], p + 1) - 1 + MOD) % MOD * invers_mod(v[i] - 1) % MOD;
            s %= MOD;
        }
    if(n > 1)
    {
        nr = 2LL * nr % MOD;
        s = 1LL * s * (n + 1) % MOD;
    }
}

void citire()
{
    int t, s, nr;
    long long n;
    f >> t;
    while(t--)
    {
        f >> n;
        suma_numar_div(n, s, nr);
        g << nr << ' ' << s << '\n';
    }
}


int main()
{
    ciur(1000000);
    citire();
}