In python / operator performs floating point division which can lead to precision errors if numbers are large. Hence your n/k does not get accurate value.
// is integer division and gives correct precision.
can someone clarify what is the mistake in my code…my code only passes 30%,thanks
below is my code,
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan=new Scanner(System.in);
int t=0,n=0,k=1,i;
if(scan.hasNextInt())
t=scan.nextInt();
for(i=0;i<t;i++)
{
if(scan.hasNextInt())
n=scan.nextInt();
if(scan.hasNextInt())
k=scan.nextInt();
int c=n/k;
if((c%k)==0)
System.out.println(“NO”);
else
System.out.println(“YES”);
It gives correct output for sample test case but gives WA for subtask 1 and TLE for subtask2. I guess for the latter, it is due to O(n^2) of second loop but I can’t figure out the faulty logic for WA.
Edit 1: Found faulty logic and fixed it here
Edit 2: Fixed TLE using the logic given here. Also implemented in cpp avoiding integer overflow-underflow here
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
class Ques2 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for (int i = 0; i <t ; i++) {
long n=s.nextInt();
long k=s.nextInt();
if(n%(k*k)==0){
System.out.println("NO");
}
else {
System.out.println("YES");
}
}
}
}
I am getting only 30 points can somebody please tell me the issue?
So question, Its given that “the second one chooses a random box with the smallest number of apples and puts K apples in it.”
so my understanding is that first he will select a box at random. Then after that he’ll randomly select from the remaining boxes and so on. Is that correct? Because at the beginning all the boxes will have zero apples