#include<bits/stdc++.h>
#define int long long
using namespace std;
vector v;
signed main()
{
int t,vec[] = {2,3,5,7,11,13,17,19,23,29},i;
cin>>t;
for(i=0;i<10;i++)
v.push_back(vec[i]);
while(t--)
{
int n,a,b,pt=0;
cin>>n>>a>>b;
if(a<=0&&n%2==0)
{
pt+=a;
n=1;
}
while(n%2==0)
{
if(a>0)
pt+=a;
n/=2;
}
if(b<=0&&n!=1)
{
pt+=b;
n=1;
}
else
{
while(n!=1)
{
for(i=0;i<10;i++)
{
if(n%v[i]==0)
{
pt+=b;
n/=v[i];
break;
}
}
}
}
cout<<pt<<endl;
}
return 0;
}
ssjgz
October 13, 2021, 8:25am
2
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
1 Like
Thanks for the suggestion…Actually i am new here so i didn’t knew that
here is the link
https://www.codechef.com/viewsolution/52386929
1 Like
ssjgz
October 14, 2021, 1:25pm
4
Thanks! Consider the test input:
1
31 1 1
1 Like
Whoa…your reply was fast !
Appreciate the help man , i understood what’s wrong with my code
btw did u used any software or any other sort of method to find this test case or u just get it by looking at it ?
1 Like
ssjgz
October 14, 2021, 1:42pm
6
This time around, I got the testcase just by looking at it
With lots of other problems, though, I often use a brute-force implementation + random testcase generator.
1 Like