Cod sursa(job #1014273)

Utilizator palcuiealexAlex Palcuie palcuiealex Data 22 octombrie 2013 13:25:11
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 2.62 kb
/***************************************************
 * Alex Palcuie
 * Romania - 2013
 * alex [dot] palcuie [at] gmail [dot] com
 * http://palcu.blogspot.com/
****************************************************/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>
#include <climits>
#include <fstream>
#include <sstream>

using namespace std;

// Defines
#define NAME(n) #n
#define prv(v,n) dbv((v), (#v), (n))
#define prw(v) dbw((v), (#v))
#define F first
#define S second
#define pb push_back
#define sz size()
#define mp make_pair
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

// Helpers
template <typename T> inline void dbv(const T * v, const char * name, int n){
	fprintf(stderr, "=== %s ===\n", name);
	for(int i=0; i<n; i++)
		cerr << v[i] << " ";
	cerr << '\n';
}
template<typename T> void dbw(const std::vector<T>& t, const char * name){
	fprintf(stderr, "=== %s ===\n", name);
	unsigned n = t.size();
	for(typename std::vector<T>::size_type i=0; i<n; ++i)
		std::cerr << t[i] << ' ';
	cerr << '\n';
}

// Structs

// Constants
const int MAX_PRIM = 1000000;
const int INF = 0x3f3f3f3f;
const int MOD = 9973;

// Globals
int n;
bitset<MAX_PRIM> isPrim;
vector<int> primes;

// Functions
void generatePrimes(){
    for(int k=2; k<MAX_PRIM; k++)
        if(!isPrim[k]){
            primes.pb(k);
            for(int j=k; j<MAX_PRIM; j+=k)
                isPrim[j] = 1;
        }
}
inline bool canDivideWith(ull x, int d){
    return (x % d == 0);
}
void solveFor(ull x){
    ull nDiv = 1, sDiv = 1, i = 0;
    ull sqrtOfX = sqrt(x);
    while(primes[i] <= sqrtOfX && x != 1){
        if(canDivideWith(x, primes[i])){
            ull d = 0, sumTerm = primes[i];
            while(canDivideWith(x, primes[i])){
                d++;
                x /= primes[i];
                sumTerm *= primes[i];
            }

            nDiv *= (d + 1);
            ull term = (sumTerm - 1) / (primes[i] - 1);
            sDiv = (sDiv * term) % MOD;
        }
        i++;
    }
    if(x != 1){
        nDiv *= 2;
        ull term = (x * x - 1) / (x - 1);
        sDiv = (sDiv * term) % MOD;
    }

    printf("%llu %llu\n", nDiv, sDiv);
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("ssnd.in", "r", stdin);
	freopen("ssnd.out", "w", stdout);
	#endif

	generatePrimes();

	scanf("%d", &n);
	for(int i=0; i<n; i++){
        ull x;
        scanf("%llu", &x);
        solveFor(x);
	}

	return 0;
}