Python in simplified terms:

for _ in xrange(input()): n,k = map(int,raw_input().split()) print "NO" if n%(k*k)==0 else "YES"

Great discussion on these forums. One can learn so much. Thank you all!

Python in simplified terms:

for _ in xrange(input()): n,k = map(int,raw_input().split()) print "NO" if n%(k*k)==0 else "YES"

Great discussion on these forums. One can learn so much. Thank you all!

We can just find **a=n/k** and then we can do **a%k** which will not give SIGFPE in C++.

1 Like

#include<bits/stdc++.h>

using namespace std;

int main()

{

int test;

cin>>test;

unsigned long long int n,k,temp;

for(auto j=0;j<test;j++){

cin>>n>>k;

if(k==1)

cout<<“NO\n”;

else{

temp=n/k;

if(temp%k==0)

cout<<“NO\n”;

else

cout<<“YES\n”;

}

}

return 0;

}

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”);

```
}
}
```

}

Numbers are as large as 10^{18} and hence overflow ‘int’ . Use ‘long’

The only condition when the final condition will be same is if N is a multiple of k*k.

Your logic works.

Sir please have a look at this code submission

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