Cod sursa(job #932575)

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

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

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

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

long long pow(int a , int b)
{
    long long rez = 1 , n = a;
    for(int i = 0 ; (1<<i) <= b ; ++i )
    {
        if((1<<i)&b)
            rez*=n;
        n*=n;
    }
    return rez;
}

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";
	}
}