Problem Code: EOEO
Link: CodeChef: Practical coding for everyone
Why does the following code results in AC for both constraints
import java.util.*;
import java.io.*;
import java.lang.Math;
public class Codechef {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
// FastScanner scanner = new FastScanner(System.in);
int t = scn.nextInt();
while (t-- > 0) {
long ts = scn.nextLong();
while (ts % 2 == 0) {
ts /= 2;
}
if(ts <= 1){
System.out.println(0);
} else{
System.out.println(ts/2);
}
}
}
and the code given below results in AC tiny for the 1st constraint:
import java.util.*;
import java.io.*;
import java.lang.Math;
public class Codechef {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
// FastScanner scanner = new FastScanner(System.in);
int t = scn.nextInt();
while (t-- > 0) {
long ts = scn.nextLong();
while (ts % 2 == 0) {
ts /= 2;
}
System.out.println((int)Math.floor(ts/2));
}
}
I’m essentially “flooring” the result in both the snippets, but why do they give different results?