can anyone tell which test case is not working in these code.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd( ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
// Function to return LCM of two numbers
ll lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;
}
int main() {
// your code goes here
ll t;
cin>>t;
while(t–){
ll k,x,c=0,i=0,j=0,min=1000000000;
cin>>k>>x;
vector v,v1;
int flag=0;
int n=x;
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////// v1 contains prime factor while v contains all factors
while (n%2 == 0)
{
if(flag==0){
flag=1;
v1.push_back(2);
}
else
v1[i]=v1[i]*2;
n = n/2;
}
flag=0;
j=i+1;
for (int i = 3; i <= sqrt(n); i = i+2)
{
flag=0;
// While i divides n, print i and divide n
while (n%i == 0)
{
if(flag==0){
flag=1;
v1.push_back(i);
}
else
v1[j]=v1[j]*i;
n = n/i;
}
j++;
}
// This condition is to handle the case when n
// is a prime number greater than 2
if (n > 2)
v1.push_back(n);
int sum=0;
for(i=0;i<v1.size();i++)
{
// cout<<v1[i]<<" ";
sum+=v1[i];
}
/////////////////////////////////////////////////////////////////////////
for ( i=1; i<=sqrt(x); i++)
{
if (x%i == 0)
{
if (i*i == x)
v.push_back(i);
else
{
v.push_back(i);
v.push_back(x/i);
}
}
}
// cout<<v1.size()<<" "<<sum;
///////////////////////////////////////////////////////////////
if(k<v1.size()){
for(i=0;i<v.size();i++)
{
for(j=i;j<v.size();j++)
{
c=0;
if(lcm(v[i],v[j])==x){
c=v[i]+v[j]+k-2;
if(c<min)
{
min=c;
}
}
}
}
}
else{
min=sum+k-v1.size();
}
cout<<min<<endl;
}
return 0;
}
How can the answer be 12?
The lcm will be 36.
First we will multiply 2^2 to 1 because 1 is minimum in the array and then we will multiply 3^2 to 1. So the lcm will be equal to X.
Correct me if i am wrong
request :
Can anyone provide the test case for which my solution fails ??
code CodeChef: Practical coding for everyone
upd : sorry my fault link is updated.
logic :
I took all the prime to there raised power for example 224 I represented it as (2^5) * (7^1), for 30 I represented it as (2^1) * (3 ^ 1) * (5 ^ 1) since they all are the power of prime so there can never be more than 7 values. so it took all these values and also 1 and did a brute force.
additional work done:
I also checked my solution by making a generator and checking on the setter solution and it looks fine to me. I would request If someone can give a look provide some feedback (sample case on which it fails).
Your link is not showing your code
sorry my fault I have updated the link
Your code have 1 or 2 syntax error. Apart from that it is giving wrong at:
1
1 90
Your is getting wrong at :
1
2 90
Answer is 19 but your code is giving 91.
input for K is greater than 1
No need to thanks. Now it’s your turn to debug mine 
https://www.codechef.com/viewsolution/39780259
first of all you should write a clean code, man it’s hard to read when no formatting is there and when you provide the code to debug to other please remove the template and make sure to also remove unused variable
1 Like
Thanks alot bro.This reply helped me out indirectly.
I was removing global unsed variables (to make it readable) , only then i realized that i am accidently not redeclaring vartiable ‘j’ at every recursion call. I changed and it got accepted.
1 Like
sorry man for me it’s hard to debug when I compiled you code in geany I gave me bunch of warnings. If you like I can provide the test case even though It would be ironic and I am not even good at debugging.
One more thing you give the same name to local variable which you gave to global variable make sure to avoid this.
1 Like
Sure ,will keep in mind next time.
For anyone else in need of test cases , here are two :
4
2 90
3 90
2 200
3 216
answer :
19
16
33
36
5
8 9
2 40
2 126
3 252
2 252
answer :
16
13
23
20
37
I did the same but it fails 
Invalid Test Case [For Official Problem]
1 90
2 ≤ K , X ≤ 10^6
my code gives answer 13 in this case but it is giving WA…
thanks man i was stuck for while ,now i got my mistake…