-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTRNO.cpp
51 lines (50 loc) · 1.29 KB
/
STRNO.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>
#define ll long long int
using namespace std;
int main() {
// your code goes here
int t;
//Input number of test cases
cin >> t;
while(t--) {
//Input x - Number of positive divisors, k - Number of prime divisors
int x,k;
cin >> x >> k;
//Set of primes factors of the number 'x'
set<int> primes;
//Powers of the prime factors of the number 'x'
map<int,int> freq;
//Check for power of 2
while(x % 2 == 0) {
primes.insert(2);
freq[2]++;
x /= 2;
}
//Check for powers of 3,5,7...till square root of 'x' (Prime factorisation method)
for (int i = 3;i <= sqrt(x);i += 2) {
while(x % i == 0) {
primes.insert(i);
freq[i]++;
x /= i;
}
}
//Check if there is something left
if (x > 2) {
primes.insert(x);
freq[x]++;
}
//sum variable is used to store all the sum of powers
int sum = 0;
//Add all the powers of the prime factors
for (auto i = primes.begin();i != primes.end();i++) {
sum += (freq[*i]);
}
//Check if sum is greater or equal to k. If yes, then 1 else 0
if (sum >= k) {
cout << 1 << "\n";
} else {
cout << 0 << "\n";
}
}
return 0;
}