Cod sursa(job #1499626)

Utilizator Balescu_OvidiuBalescu Ovidiu-Gheorghe Balescu_Ovidiu Data 10 octombrie 2015 22:04:46
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <iostream>
#include <fstream>
using namespace std;

long long pow(unsigned long long n, unsigned long long p){
    long long x=1;
    while(p){
        if(p&1){
            x*=n;
            p--;
        }
        n*=n;
        p>>=1;
    }
    return x;
}
int main(){
    unsigned t; unsigned long long n;
    ifstream f("ssnd.in");
    f>>t;
	cout<<t;
    ofstream g("ssnd.out");
    while(t--){
        f>>n;
        unsigned long long q=0,Q=1,x=3,suma=1;
        while(n%2==0&&n>1){
            n/=2;
            q++;
			
        }
        if(q){
            Q*=q+1;
            suma*=pow(2,q+1)-1;
        }
        while(n>1){
            q=0;
            while(n%x==0){
                q++;
                n/=x;
            }
            if(q){
                Q*=q+1;
                suma*=(pow(x,q+1)-1)/(x-1);
            }
            x+=2;
        }
		if(Q==1)
            q=2;
		g<<Q<<' '<<suma%9973<<'\n';
    }
    f.close();
    g.close();
    return 0;
}