-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCount Divisors of Factorial
61 lines (55 loc) · 1.3 KB
/
Count Divisors of Factorial
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
//https://practice.geeksforgeeks.org/problems/count-divisors-of-factorial/0?fbclid=IwAR3RsG4Ad7Z-g8RtxBos7BFT7fdUucqy5ByUiG26_CRZPwQnQHO9hVZ5g28
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
//Silver_Lining
void PrimeFactor ( ll n , vector < ll > &v )
{
ll arr [ n + 1 ] ;
memset ( arr , 0 , sizeof ( arr ) ) ;
for ( ll i = 2 ; i <= n ; i ++ )
{
if ( arr [ i ] == 0 )
{
v.push_back ( i ) ;
ll k = 2 ;
while ( i * k <= n )
{
arr [ i * k ] = 1 ;
k ++ ;
}
}
}
}
ll Lagendre ( ll n , ll prime )
{
ll c = 0 ;
while ( n > 0 )
{
n = n / prime ;
c += n ;
}
return c ;
}
int main() {
ll T ;
cin >> T ;
while ( T-- )
{
ll n , ans = 1 ;
cin >> n ;
vector < ll > prime ;
PrimeFactor ( n , prime ) ;
/* for ( ll i = 0 ; i < prime.size() ; i ++ )
cout << prime [ i ] << " " ;
cout << endl ;*/
for ( ll i = 0 ; i < prime.size() ; i ++ )
{
ll c = Lagendre ( n , prime [ i ] ) + 1 ;
ans = ans * c ;
}
cout << ans << endl ; ;
}
//code
return 0;
}