Strange Counter

  • + 0 comments

    My solution public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long t =in.nextLong();
        long v=3,i=1,v1=3;
        while(i<=t)
            {
            if(v1==1)
                {
                i=i+1;
                v=v*2;
                v1=v;
            }
            else
                {
                i=(i+v-1);
                v1=1;
            }
        }
        if(i==t)
            {
            System.out.println(v1);
        }
        else
            {
            System.out.println(i-t+1);
        }
    }
    

    }