Cod sursa(job #1349839)

Utilizator alexandru.ghergutAlexandru-Gabriel Ghergut alexandru.ghergut Data 20 februarie 2015 15:21:45
Problema Suma si numarul divizorilor Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 1.43 kb
#include <fstream>
#include <iostream>
#include <cmath>
using namespace std;

#define max 1000000
void sieveOfEratosthenes(bool a[]);
unsigned long long modPow(int base, int exp);

int main()
{
    int t, i;
    long long n;
    bool sieve[max + 1];
    sieveOfEratosthenes(sieve);

    ifstream f("ssnd.in");
    f >> t;
    int card, p, j;
    unsigned long long s;
    ofstream g("ssnd.out");
    for (i = 1; i <= t; i++)
    {
        f >> n;
        card = s = 1;
        for (j = 2; j <= max; j++)
            if (sieve[j])
            {
                p = 0;
                while (n % j == 0)
                {
                    p++;
                    n /= j;
                }
                if (p)
                {
                    card *= (p + 1);
                    s *= (((modPow(j, p + 1) - 1) / (j - 1)) % 9973);
                }
            }
        g << card << " " << s % 9973 << "\n";
    }
    f.close();
    g.close();

    return 0;
}

void sieveOfEratosthenes(bool a[])
{
    int i, j;
    for (i = 2; i <= max; i++)
        a[i] = true;

    for (i = 4; i <= max; i += 2)
        a[i] = false;
    for (i = 3; i <= sqrt(max); i++)
        for (j = i * i; j <= max; j += i + i)
            a[j] = false;
}

unsigned long long modPow(int base, int exp)
{
    unsigned long long result = 1;
    while (exp)
    {
        if (exp & 1)
            result *= base;
        base *= base;
        exp >>= 1;
    }

    return result;
}