-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcp17.cpp
52 lines (45 loc) · 1.11 KB
/
cp17.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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5;
vector<ll> primes;
bool isprime[MAXN] = {true};
void prime_seive(){
isprime[1] = false;
for(ll i= 2; i*i <= MAXN; i++){
if(isprime[i]){
for(ll j=i*i; j<MAXN; j+=i){
isprime[j] = false;
}
}
}
for(ll i=0; i<MAXN; i++){
if(isprime[i]){
primes.push_back(i);
}
}
}
ll factor_nk(int n, int k){
ll ans = 0;
for(int p:primes){
if(n%p == 0){
//if p is a prime factor of N
int power_of_p = 0;
int m = n;
while(m%p == 0){
m/=p;
power_of_p++;
}
//N = p1^power_of_p1 * p2^power_of_p2
if(p == 2){
//power of 2 in N^2/4 would be 2*power of p - 2;
ans = (ans * (k * power_of_p -2 + 1));
}else{
ans = (ans * (k * power_of_p + 1));
}
}
}
//ans = factors(N^2 / 4) if N is even
//ans = factors(N^2) if N is odd
return ans * 2;
}