Pagini recente » Cod sursa (job #597197) | Cod sursa (job #2979813)
#include <bits/stdc++.h>
using namespace std;
struct fact
{
long long factor, power;
};
int main()
{
ifstream fin;
fin.open("ssnd.in");
ofstream fout;
fout.open("ssnd.out");
vector<fact> f_p;
long long n = 1000000;
short int arr[n+5];
for(int i = 1; i <= n; i++)
{
arr[i] = 0;
}
arr[0] = 1;
arr[1] = 1;
for(long long i = 2; i < (n+1)/2; i++)
{
if(arr[i] == 0)
{
long long current = i*2;
while(current <= n)
{
arr[current] = 1;
current+=i;
}
}
}
int t = 0;
fin >> t;
for(int q = 0; q < t; q++)
{
long long n = 0;
fin >> n;
int val = 2;
f_p.clear();
vector<long long> factorisation;
while(n != 1)
{
if(arr[val] == 0)
{
if(n % val == 0)
{
factorisation.push_back(val);
n/=val;
}
else
{
val++;
}
}
else
{
val++;
}
}
//for(int i = 0; i < factorisation.size(); i++)
//cout << factorisation[i] << ' ';
factorisation.push_back(1);
int len = factorisation.size();
int pos = 0;
int powerr = 1;
for(int i = 0; i < len-1; i++)
{
if(factorisation[i] == factorisation[i+1])
{
powerr++;
}
else
{
struct fact abc;
abc.power = powerr;
abc.factor = factorisation[i];
f_p.push_back(abc);
pos++;
powerr = 1;
}
}
long long n_div = 1;
long long suma = 1;
for(int i = 0; i < pos; i++)
{
//cout << f_p[i].power << ' ';
n_div *= f_p[i].power + 1;
suma *= (pow(f_p[i].factor, f_p[i].power + 1)-1) / (f_p[i].factor - 1);
}
fout << n_div << ' ' << suma << '\n';
}
}