Cod sursa(job #2203877)

Utilizator andrei13Paval Andrei andrei13 Data 13 mai 2018 15:57:09
Problema Suma si numarul divizorilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

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

#define mod 9973;

int t;
int power(int a,int b)
{
    int prod=1;
    for(int i=1;i<=b;++i)
        prod*=a;
    return prod;
}
void fct(int n,int &nr,int &s)
{
    nr=1,s=1;
    int p=0;
    while(n%2==0)
        n/=2,++p;
    if(p)
    {
        nr*=p+1;
        s=power(2,p+1)-1;
    }
    for(int d=3; d*d<=n; d+=2)
        {
            p=0;
            while(n%d==0)
                n/=d,++p;
            if(p)
            {
                nr*=p+1;
                s=(s*(power(d,p+1)-1))/(d-1);
                s%=mod;
            }
        }
    if(n!=1)
        {
            nr*=2;
            s=(s*(n+1))%mod;
        }
}
int main()
{
    int n,s1,s2;
    f>>t;
    while(t)
    {
        f>>n;
        fct(n,s1,s2);
        g<<s1<<' '<<s2<<endl;
        --t;
    }
    return 0;
}