Cod sursa(job #754714)

Utilizator visanrVisan Radu visanr Data 2 iunie 2012 23:02:44
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.73 kb
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
using namespace std;


#define nmax 1000040
#define mod 9973

long long pr[nmax >> 2];
bool sv[nmax];

void ciur()
{
     int i, j;
     for(i = 2; i <= nmax; i++) sv[i] = true;
     for(i = 2; i <= nmax; i++)
     {
           if(sv[i])
           {
                    pr[++pr[0]] = (long long)(i);
                    for(j = 2 * i; j <= nmax; j += i) sv[j] = false;
           }
     }
}

int lgput(long long a, long long b)
{
    if(!b) return 1;
    if(b % 2) return (a * lgput(a, b - 1)) % mod;
    long long x = lgput(a, b / 2) % mod;
    return (x * x) % mod;
}

int main()
{
    freopen("ssnd.in", "r", stdin);
    freopen("ssnd.out", "w", stdout);
    int i, j, t;
    long long n, aux, nr, sum, exp;
    ciur();
    scanf("%i", &t);
    for(i = 0; i < t; i++)
    {
          cin >> n;
          nr = 1, sum = 1;
          for(j = 1; pr[j] * pr[j] <= n; j++)
          {
                if(n % pr[j] == 0)
                {
                     exp = 0;
                     while(n % pr[j] == 0)
                     {
                             n /= pr[j];
                             exp++;
                     }
                     nr *= (exp + 1);
                     long long aux1 = (lgput(pr[j], exp + 1) - 1) % mod;
                     long long aux2 = (lgput(pr[j] - 1, mod - 2)) % mod;
                     sum=(((sum * aux1) % mod) * aux2) % mod; 
                }
          }
          if(n != 1)
          {
               nr *= 2;
               sum = (sum * (n + 1)) % mod;
          }
          cout << nr << " " << sum << "\n";
    }
    scanf("%i", &i);
    return 0;
}