Cod sursa(job #659759)

Utilizator slycerdan dragomir slycer Data 10 ianuarie 2012 22:35:37
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.75 kb
/* 
 * File:   Sumasinumaruldivizorilor.cpp
 * Author: slycer
 *
 * Created on January 10, 2012, 9:27 PM
 */

#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
using namespace std;

/*
 * 
 */
const int MOD = 9973; 
int main(int argc, char** argv) {

    ifstream input("ssnd.in");
    ofstream output("ssnd.out");
    
    int * prime = new int[1000001]; 
    long long * pacc = new long long[1000001]; 
    int cap=0; 
    for ( int i=0; i<=1000000; i++){
        prime[i] = 0; 
    }
    for ( int i=2; i<=1000000; i++){
        if ( prime[i] == 0 ){
            pacc[cap++] = i; 
            for ( int j=i+i; j<=1000000; j+=i ){
                prime[j] = 1; 
            }
        }
    }
    
    
    int n; 
    input >> n; 
    for ( int i=0; i<n; i++ ){
        long long c; 
        input >> c; 
        long long aux = c; 
        long long suma = 1; 
        long long produs = 1; 
        for ( int j=0; pacc[j]*pacc[j]<=c; j++ ){
            int cnt=0; 
            long long factor = 1; 
            while ( aux % pacc[j] == 0 ){
                aux = aux/pacc[j]; 
                cnt++; 
                factor = factor * pacc[j]; 
            }
            if ( cnt> 0 ){
                factor = factor * pacc[j]; 
                produs = produs * ( cnt + 1 );
                factor = ( factor -1 )/( pacc[j] - 1);
                factor = factor % MOD; 
                suma = suma * factor; 
                suma = suma % MOD; 
            }
        }
        if ( aux > 1 ){
            produs = produs * 2; 
            long long factor = ( aux * aux - 1 )/( aux - 1 ); 
            factor = factor % MOD; 
            suma = ( suma * factor ) % MOD; 
        }
        output << produs << " " <<  suma <<"\n";
    }
    
    return 0;
}