code: https://ide.codingblocks.com/s/456135
prob: https://codeforces.com/problemset/problem/1294/C
output for 97 and 12345 is not correct
code: https://ide.codingblocks.com/s/456135
prob: https://codeforces.com/problemset/problem/1294/C
output for 97 and 12345 is not correct
hello @raghav007
what u r trying here?
u r complicating it . this problem is very straight , u just have to find the first factor of n say a.
and then again repeat the same on n/a.
put all factors in set.
check this->
int n;
cin >> n;
set<int> used;
for (int i = 2; i * i <= n; ++i) { //finding first factor of n
if (n % i == 0 && !used.count(i)) {
used.insert(i);
n /= i;
break;
}
}
for (int i = 2; i * i <= n; ++i) { //finding first factor of n
if (n % i == 0 && !used.count(i)) {
used.insert(i);
n /= i;
break;
}
}
if (int(used.size()) < 2 || used.count(n) || n == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
used.insert(n);
for (auto it : used) cout << it << " ";
cout << endl;
}
my approach:
find total factors if they are more than 3 cout yes, if there is one factor and it’s power >= 6 then yes ,
if for example n = 24 then c = n/a.b if c is unique then yes ( c = (24/2*3) ) else no
why are they using the for loop twice in the editorial
…
first loop is to find the smallest factor . let say u get a.
now u divide n by a.
so u left with n/a.
now u again have find the smallest factor of n/a (say it is b) for that they are using second loop , but b should be not equal to a. thats why they are using set to check whether the factor b is equal to a or its new.
if new then stop execution of second loop.
so this is how u get
a , b , n/(a,b) as three distinct number.
what if u have only two factors?
this is the case for 2 factors where a and b are the prime factors
how about 6.
for for n=6 u will have
{2,3,1} but as per constraints all 3 number shoudl be greater than 1
Print “NO” if it is impossible to represent n as a⋅b⋅c for some distinct integers a,b,c such that 2≤a,b,c
they wont give 6 as input
they can give any value greater that 2.
also u are printing factor[0],factor[1],factor[2], in place of factor[2], it should be
temp/(factor[0]*factor[1]) becuase product should be equal to n
also the logic for a, aa, aa*a is not correct .
they way u r calculating count is not correct. it will have count of more than one factors .
it will give no for 6 because 1 is less than 2 but in the question they are asking for a,b,c >= 2
count is the power of a factor
check now->
thanks a lot it got accepted
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.