edited by
461 views
2 votes
2 votes
I take an integer $n$ .If $n$ is even, I divide it by $2$, if it is odd, I multiple $n$ by $3$ and add one to the product.I keep doing this till the number reduces to $1$.If I start with $5$ for example,I reach $1$ in $5$ steps. $(16, 8, 4, 2, 1)$. $7$ takes $16$ steps to reach $1$.
The number between $1$ and $2000000000$ that requires the largest number of steps to reach $1$ this way is?
edited by

1 Answer

0 votes
0 votes

Try code below 

#include<stdio.h>
int main(){
    long int count,lcount=0,i,temp,temp1,num;
    for(i=100000;i<=2000000000;i++){
        temp=i;
        count=0;
        while(temp!=1){
            if(temp&1){
                temp1=temp;
                temp=temp<<1L;
                temp+=temp1;
                temp++;
                count++;
            }
            else{
                temp=temp>>1L;
                count++;
            }
        }
        printf("%ld\n",i );
        if(count>lcount){
            lcount=count;
            num=i;
        }
    }
    printf("%ld\n",lcount );
    printf("%ld\n",num );
    return 0;
}

It will give you both number of step and largest number

Related questions

2 votes
2 votes
1 answer
1
Amit pal1410 asked Nov 15, 2017
304 views
The largest value of $min(2+x^2,6−3x)$ when $x>0$ is$11$$22 $$33 $$4$
0 votes
0 votes
1 answer
2
set2018 asked Dec 13, 2017
672 views
If N = 15! – 13!, then the largest prime number that divides N is _____________.
1 votes
1 votes
1 answer
3
0 votes
0 votes
1 answer
4
soorajchn asked Mar 14, 2015
5,457 views
a) n- ( lg(n)) - 2b) n + (lg(n)-2)