Cod sursa(job #2381556)

Utilizator _Victor_Victor Ciobanu _Victor_ Data 16 martie 2019 23:41:23
Problema Suma si numarul divizorilor Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include <bits/stdc++.h>
#define MAX 1000010
#define MOD 9973
using namespace std;

bool E[MAX];
vector <int> V;
int n,b,c,ne=1,se=1;

//Suma si numarul divizorilor

int inv(int a,int b,int &x,int &y){
	if(b==0){
		x=1;
		y=0;
		return a;
	}
	int x0,y0,s;
	s=inv(b,a%b,x0,y0);
	x=y0;
	y=x0-a/b*y0;
	return s;
}

int main(){
	ifstream cin("ssnd.in");
	ofstream cout("ssnd.out");
	for(int i=2;i<=MAX;i++){
		if(!E[i]){
			V.push_back(i);
			for(int j=i*i;j<=MAX && j>0;j++){
				E[i]=1;
			}
		}
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c;
		b=c;
		int j=0;
		while(b>1){
			int x,y;
			if(b%V[j]==0){
				//V[j]
				int counter=1,prod=V[j];
				while(b%V[j]==0){
					b/=V[j];
					counter++;
					prod*=V[j];
				}
				ne*=counter;
				inv(V[j]-1,MOD,x,y);
				while(x<0)x+=MOD;
				se*=(prod-1)%MOD*x;
				se%=MOD;
			}
			if(V[j]>sqrt(c) && b>1){
				//b
				inv(b-1,MOD,x,y);
				while(x<0)x+=MOD;
				se*=(b*b-1)%MOD*x;
				se%=MOD;
				ne*=2;
				b=1;
			}
			j++;
		}
		cout<<ne<<' '<<se<<'\n';
		ne=se=1;
	}
	return 0;
}