# Codeforces educational round 84

``````import java.util.*;
class Rextester{
static boolean odd(int n){
if(n%2==0)
return false;
return true;
}
static boolean solve(int n, int k)
{
if (n >= k*k) {
return true;
}
return false;
}
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
int test=in.nextInt();
while(test-- >0){
int n, k;
n=in.nextInt();
k=in.nextInt();
if(odd(n) && odd(k)){
if(solve(n, k)){
System.out.println("YES");
continue;
}
}
if(!odd(n) && !odd(k)){
if(solve(n, k)){
System.out.println("YES");
continue;
}
}
System.out.println("NO");
}
}
}
``````

https://codeforces.com/contest/1327/problem/A

The answer would be â€śYESâ€ť iff n and k both would be even or both would be odd and n >= k*k else answer would be â€śNOâ€ť
This is what I did.

1 Like

1
1000000 1100000

take k long

isnâ€™t that what I did? I think it should work.

getting yes for this test case. I think that is correctâ€¦

OK i was getting buffer overflow errorâ€¦ should be long instead of int. THanks for help

Was it a pretty known trick? I see so many solutions using this but I didnâ€™t know that earlier

1 + 3 + 5 + 7...2n-1 is n^2

1 Like

Why this condition doesnâ€™t work :-
if( (n%2==0 && k%2==0) || (n%2!=0 && k%2!=0) && ( (n/k) >= k) )

But this one works :-
if( (n%2==k%2) && ((n/k) >= k) )

Because hierarchy of logical operators says that in a statement, first all the logical NOT(!) should be processed, then logical AND(&&), and then logical OR(||).

So according to the first thing, condition 2 AND condition 3 should work. After that, if condition 1 OR the other two condition work, it will process the statements under it. This problem can be resolved by putting a bracket before condition 1, and after condition 2.

2 Likes

No, Most of us derived it quickly, it comes from practice !

k>=sqrt(n)