Pagini recente » Cod sursa (job #1769174) | Cod sursa (job #2121551) | Cod sursa (job #3175985) | Cod sursa (job #2301919) | Cod sursa (job #1017228)
#include <iostream>
#include <fstream>
#include <map>
#include <math.h>
#define MAXC 2000000
using namespace std;
typedef unsigned long long int ulong;
typedef map<int,int> dict;
typedef map<int,int>::iterator it;
int ciur(int *n, int l)
{
n[0] = n[1] = 1;
for(int i = 2; i < l; i++)
if(n[i] == 0)
for(int j = i + i; j < l; j+=i)
n[j] = 1;
return 0;
}
int build(ulong n, int* C, dict* b)
{
if(n <= 1) return 0;
for(int i = 2; i < MAXC; i++)
{
if(C[i] == 0)
{
if(n % i == 0)
{
(*b)[i]++;
build(n/i, C, b);
break;
}
}
}
return 0;
}
int compute(dict d, int *div, ulong *sum)
{
*div = 1;
*sum = 1;
it a = d.begin();
it b = d.end();
do
{
*div *= a->second + 1;
ulong x = (ulong)pow(a->first, a->second + 1) - 1;
ulong y = a->first - 1;
*sum *= (x / y);
a++;
}
while(a != b);
*sum %= 9973;
return 0;
}
int main()
{
int t;
ifstream fin("ssnd.in");
ofstream fout("ssnd.out");
fin>>t;
ulong *A = new ulong[t];
for(int i = 0; i < t; i++)
fin>>A[i];
int* C = new int[MAXC];
for(int i = 0; i < MAXC; i++) C[i] = 0;
ciur(C, MAXC);
dict B;
int d = 0;
ulong s = 0;
for(int i = 0; i < t; i++)
{
B.clear();
build(A[i], C, &B);
compute(B, &d, &s);
fout<<d<<" "<<s<<"\n";
}
fout.close();
return 0;
}