My code is resulting in Wrong Answer and I’m not able to figure out why. I have tried a few test cases, though I am not able to figure out why it’s a wrong answer.
Problem Link: https://www.codechef.com/problems/NUMFACT/
My Submission: https://www.codechef.com/viewsolution/28520934
#include <bits/stdc++.h>
using namespace std;
multiset<int> p;
multiset<int>::iterator it;
void primes(int n) {
while (n % 2 == 0) {
p.insert(2);
n = n / 2;
}
for (int i = 3; i < sqrt(n); i = i + 2) {
while (n % i == 0) {
p.insert(i);
n = n / i;
}
}
if (n > 2) { p.insert(n); }
}
int main() {
int t = 0;
cin >> t;
for (int j = 0; j < t; j++) {
int n = 0, y = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> y;
primes(y);
}
int facts = 1, pr = -1;
for (it = p.begin(); it != p.end(); it++) {
if (*it == pr) { continue; }
facts *= (p.count(*it)+1);
pr = *it;
}
cout << facts << "\n";
p.clear();
}
return 0;
}
Please help.