Pagini recente » Cod sursa (job #955695) | Cod sursa (job #567500) | Cod sursa (job #601481) | Cod sursa (job #822321) | Cod sursa (job #1654995)
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
using namespace std;
ifstream f("ssnd.in");
ofstream g("ssnd.out");
int64_t pown(int64_t a,int64_t b,int64_t m)
{
int64_t p=1;
while(b)
{
if(b%2)
p=(p*a)%m,b--;
a=(a*a)%m;
b/=2;
}
return p;
}
void gdc(int64_t a,int64_t b,int64_t &x,int64_t &y)
{
if(!b)
{
x=1;
y=0;
return;
}
else
{
int64_t x0,y0;
gdc(b,a%b,x0,y0);
x=y0;
y=x0-y0*(a/b);
}
}
int64_t inv_modular(int64_t a,int64_t b)
{
int64_t x,y;
gdc(a,b,x,y);
while(x<0)
x+=b;
return x;
}
int main()
{
vector <bool> ciur(1000005);
ciur[0]=ciur[1]=1;
for(int i=2;i<1e6+2;i++)
if(!ciur[i])
for(int j=i+i;j<1e6+2;j+=i)
ciur[j]=1;
int t;
int64_t x;
f>>t;
while(t--)
{
int64_t p=1,s=0;
f>>x;
if(x<1e6 && !ciur[x])
{
g<<"2 "<<1+x<<"\n";
continue;
}
for(int i=2;i<=sqrt(x);i++)
if(!ciur[i])
{
int k=1,y=x;
while(y%i==0)
k++,y/=i;
p*=k;
p%=9973;
if(s==0)
s=(pown(i,k,9973)-1)*inv_modular(i-1,9973) % 9973;
else
s=(s*(pown(i,k,9973)-1)*inv_modular(i-1,9973)) % 9973;
}
g<<p<<" "<<s<<"\n";
}
}