Sherlock and Special Count
Practice
3.9 (14 votes)
Algorithms
Approved
Math
Medium
Open
Problem
61% Success 1317 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Let's say P= [P1, P2 . . . PN] is a permutations of all positive integers less than or equal to N. A function called "special count" F(P) is defined as:

img

Now Watson gives a N and K to Sherlock and asks if K is a possible special count for any permutation of first N positive integers.

Input
First line contains T, the number of test cases. Each test case consists of N and K in one line.

Output
For each test case, print "YES" or "NO", denoting whether K is a possible special count or not.

Constraints
1 ≤ T ≤ 100
20% testdata: 1 ≤ N ≤ 10
20% testdata: 1 ≤ N ≤ 20
60% testdata: 1 ≤ N ≤ 40
0 ≤ K ≤ 2000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
Basic ProgrammingBasics of ImplementationHiringImplementationMedium
Points:30
5 votes
Tags:
Basic Programming
Points:20
8 votes
Tags:
MathematicsEasy