Mai intai trebuie sa te autentifici.
Cod sursa(job #1168909)
Utilizator | Data | 9 aprilie 2014 21:27:31 | |
---|---|---|---|
Problema | Suma si numarul divizorilor | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 1.62 kb |
#include <fstream>
#include <vector>
using namespace std;
const int MAXN = 1000001;
const long long MOD = 9973;
unsigned long long n,x,cx;
unsigned long long no_d, sum_d, d, exp;
bool p[MAXN];
vector<int> primeNumbers;
long long power(long long base, long long exp)
{
if (exp == 1)
return base;
else
{
if (exp%2)
return base*power(base*base, (exp-1)/2);
else
return power(base*base, exp/2);
}
}
void sieve()
{
p[0] = p[1] = true;
unsigned int i, j;
primeNumbers.push_back(2);
for (i=3; i<MAXN; i+=2)
{
if (!p[i])
{
primeNumbers.push_back(i);
for (j=i*i; j<MAXN; j+=i)
p[j]=true;
}
}
}
int main()
{
ifstream fin("ssnd.in");
ofstream fout("ssnd.out");
sieve();
fin>>n;
for (int k=1; k<=n; ++k)
{
fin>>x;
cx=x;
no_d = 1;
sum_d = 1;
for (vector<int>::iterator it = primeNumbers.begin(); it != primeNumbers.end() && cx!=1; ++it)
{
d = *it;
exp = 0;
while (cx != 1 && cx%d == 0)
{
cx/=d;
++exp;
}
no_d = (no_d * (exp+1))%MOD;
sum_d = (sum_d*(power(d, exp+1) -1)/(d-1))%MOD;
if (cx<MAXN)
{
if (!p[cx])
{
no_d=(no_d*2)%MOD;
sum_d=((sum_d)*(cx+1))%MOD;
break;
}
}
}
fout<<no_d<<' '<<sum_d<<'\n';
}
fin.close();
fout.close();
return 0;
}