Problem link -LINK
Author-Rishabh Verma
Editorialist - Rishabh Verma
Difficulty :
cakewalk
Problem
You have a given a number and you have to make it 1 by 2 ways . If the number is even then divide the number by 2 and if the number is odd then multiply it by 3 and add 10.
Explanation
Follow the que and do the same using while loop .
MY Solution
#include<bits/stdc++.h>
using namespace std;
int main(){
int t; cin>>t;
while(t--){
int n; cin>>n;
cout<<n<<" ";
while(n!=1){
if(n&1) {
n = (n*3)+1;
cout<<n<<" ";
}
else {
n/=2;
cout<<n<<" ";
}
}
cout<<endl;
}
return 0;
}