Cod sursa(job #932579)

Utilizator andreifirstCioara Andrei Ioan andreifirst Data 29 martie 2013 00:39:32
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <fstream>
#include <iostream>
#include <bitset>
using namespace std;

ifstream f("ssnd.in"); ofstream g("ssnd.out");

const int nmod=9973;
const int nmax=1000000;
const int snmax=1000;

bitset <nmax+5> ciur; 
int prim [80000];
int i, j, t, m, q;
long long n, s, nr, p, pp;

long long pow (long long b, long long p){
	if (p==1) return b;
	long long xx = pow (b, p/2);
	if (p%2) return b*xx*xx;
	else return xx*xx;
}

int main(){
	prim[++t]=2;
	for (i=3; i<=snmax; i+=2){
		if (ciur[i]==0){
			prim[++t]=i;
			for (j=i*i; j<=nmax; j+=2*i){
				ciur[j]=1;
			}
		}
	}
	for (i=snmax+1; i<=nmax; i+=2){
		if (ciur[i]==0)	prim[++t]=i;
	}
	
	f>>q;
	while (q--){
		f>>n;
		s=nr=m=1;
		while (n!=1){
			while (n%prim[m]) m++;
			p=0;
			while (n%prim[m] == 0){
				p++;
				n/= prim[m];
			}
			nr*=p+1;
			
			pp = pow (prim[m], p+1);
			s*=(pp-1)/(prim[m]-1);
			s%=nmod;
		}
		g<<nr<<" "<<s<<"\n";
	}
}