We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static long strangeCounter(long t) {
long cycleStart = 1;
long cycleValue = 3;
while (t > cycleStart + cycleValue - 1) {
cycleStart += cycleValue;
cycleValue *= 2;
}
return cycleValue - (t - cycleStart);
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
long t = Long.parseLong(bufferedReader.readLine().trim());
long result = Result.strangeCounter(t);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strange Counter
You are viewing a single comment's thread. Return to all comments →
import java.io.*;
class Result {
}
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
}