-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSigma_Function.cpp
166 lines (134 loc) · 3.79 KB
/
Sigma_Function.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/// BISMILLAHIR RAHMANIR RAHEEM
/// ALLAH IS WATCHING ME
/// ALLAH save us from COVID-19.Amin.
/// █▀█─█──█──█▀█─█─█
/// █▄█─█──█──█▄█─█▄█
/// █─█─█▄─█▄─█─█─█─█
/// كُلُّ نَفْسٍ ذَآئِقَةُ الْمَوْت
/// Every soul shall taste death.
/// Author : Md Mehraj Hossain
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp> //order_of_key return number of elements less than x, find_by_order return index (pointer use kora lgbe)
using namespace std;
using namespace __gnu_pbds;
#define ull unsigned long long
#define ll long long
#define MOHAMMAD ios::sync_with_stdio(0);cin.tie(0);
#define ses "\n"
#define all(x) (x).begin(), (x).end()
#define INF ((int)2e18)
#define pi 2*acos(0.0)
#define AE cout << fixed << setprecision(8);
string digit="0123456789";
string small="abcdefghijklmnopqrstuvwxyz";
string capital="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};
const ll MAXN=1e7;
const ll MOD = 1e9+7;
template <class T> inline T bigmod(T p,T e,T M)
{
if(e==0)
return 1;
if(e%2==0)
{
ll t=bigmod(p,e/2,M);
return (T)((t*t)%M);
}
return (T)((ll)bigmod(p,e-1,M)*(ll)p)%M;
}
template <class T> inline T modinverse(T a,T M)
{
return bigmod(a,M-2,M); // when M is prime;
}
typedef tree< ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/// Fast read.
template<class T>inline bool read(T &x)
{
int c=getchar();
int sgn=1;
while(~c&&c<'0'||c>'9')
{
if(c=='-')
sgn=-1;
c=getchar();
}
for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())
x=x*10+c-'0';
x*=sgn;
return ~c;
}
//*********************************************** The END **********************************************************************************************************************************
/////////////////////////////////////////////////////////////////////////////
vector<ll> primes;
bitset<MAXN+1> bs;
void sieve()
{
bs.set();
bs[0]=bs[1]=0;
primes.push_back(2);
for(ll i=4; i<=MAXN; i+=2)
bs[i]=0;
for(ll i=3; i<=MAXN; i+=2)
{
if(bs[i])
{
primes.push_back(i);
for(ll j=i*i; j<=MAXN; j+=i<<1)
{
bs[j]=0;
}
}
}
}
ll Sigma_Function(ll n)
{
ll sum=1;
for(ll i=0; i<primes.size() and primes[i]*primes[i]<=n; i++)
{
ll p=primes[i],prod=p;
while(n%p==0)
{
n/=p;
prod*=p;
}
if(prod>p)
{
sum*=(prod-1)/(p-1);
}
}
if(n>1)
{
sum*=(n*n-1)/(n-1);
}
return sum;
}
////////////////////////////////////////////////////////////////////////////
//main function is here.........
int main()
{
MOHAMMAD
sieve();
ll t,n;
cin >> t;
while(t--)
{
cin >> n;
cout << Sigma_Function(n) << '\n';
}
}
/*
sigma(12) = 1 + 2 + 3 + 4 + 6 + 12
= 28
sigma(2^2 * 3^1) = (2^3-1) (3^2-1)
------- * -------
2-1 3-1
= 7 * 4
= 28
Alhamdulillah
*/