Cod sursa(job #2514724)

Utilizator Sho10Andrei Alexandru Sho10 Data 26 decembrie 2019 18:09:17
Problema Suma si numarul divizorilor Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.77 kb
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,t,e=0,ans=0,sum=0,d=0,v[2000010],q=0;
bitset<2000010>m;
ll putere(ll,ll);
int32_t main(){
    ifstream cin("ssnd.in");
    ofstream cout("ssnd.out");
CODE_START;
m[2]=0;
v[q]=2;
q++;
for(ll i=3;i<=1e6-100;i=i+2){
    if(m[i]==0){
        v[q++]=i;
        for(ll j=i+i;j<=1e6;j=j+i){
            m[j]=1;
        }
    }
}
cin>>t;
while(t--){
        cin>>n;
        sum=1;
ans=1;
for(ll i=0;n!=1LL&&v[i]*v[i]<=n;i++){
        if(n%v[i]==0){
            d=v[i];
            e=1;
            while(n%d==0){
                e++;
                n=n/d;
            }
        ans=ans*e;
        ll x;
        x=putere(d,e);
        x--;
        if(x<0) x=x+9973LL;
                x=x*putere((d+9972LL)%9973LL,9971LL)%9973LL;
                sum=sum*x%9973LL;
}
}
if(n!=1){
    d=n%9973LL;
    e=2;
    ans=ans*e;
        ll x;
        x=putere(d,e);
        x--;
        if(x<0) x=x+9973LL;
                x=x*putere((d+9972LL)%9973LL,9971LL)%9973LL;
                sum=sum*x%9973LL;
}
cout<<ans<<' '<<sum<<'\n';
}
}

ll putere(ll a,ll b) {
	if (b==0)
		return 1;
	if (b==1)
		return a%9973LL;
	else {
		ll c=putere(a,b/2);
		c=c*c;
		if (b%2==0)
			return c%9973LL;
		else
			return ((a%9973LL)*(c%9973LL))%9973LL;
	}
}