The number of minimum steps must be determined for an integer N to reach 0, following these rules: 1) If N is the product of two numbers a and b, other than 1, then replace N with the max (a, b) 2) Otherwise, replace N with N-1
Example: The number 36 has 5 steps to get to 0 because:
36-->6-->3-->2-->1-->0
This because 36 = 6 * 6, N changes to the maximum (6). Then 6 = 3 * 2, N changes to the maximum (3). Note that if in 36 they had taken a and b as 18 and 2, then the number of steps would have been 6, so it would not be the minimum.
36-->18-->9-->3-->2-->1-->0
Entry: An integer Q that will be the number of cases to evaluate, next to Q times the integer N that we want to evaluate. Exit: Minimum number of steps to bring each number to 0
Solution attempt: #include #include
using namespace std;
int Q, N, i, a, b;
int main(){
cin>> Q;
for (i=0;i<Q;i++){
cin>>N;
int contador = 0;
int l = N;
for (int k=0;k<N;k++){
if (l>0 && l == a*b){
l=max(a,b);
contador ++;
}
else if (l>0){
l=l-1;
contador ++;
}
}
cout<<contador<<endl;
}
return 0;
}
However, I did not know how to determine the two numbers a and b that multiplied den N.