Squares on Grid Lines

시간 제한4초메모리 제한2048 MB

요약
쿼리로 주어진 넓이마다 n x n 격자 안에서 네 변의 점을 꼭짓점으로 하는 정사각형의 배치 수를 세고, 무한히 많으면 -1을 출력한다.
난이도

어려움10점 중 8점

유형
기하, 수학, 조합론, 누적 합
정답자
아직 제출이 없습니다

문제

You have a square of side length nn on a 2D plane, partitioned into a grid of 1×11 \times 1 square cells, totaling n2n^2 cells.

Your task is to answer qq queries, numbered from 11 to qq, described below. In query ii, you are given a real number s_is\_i, and you must count the number of ways to place four points on the plane such that

  • each point lies on the boundary of a cell (not necessarily the same), and
  • the four points form the vertices of a square with area s_is\_i.

Here, the edges of the square formed by these points do not need to be parallel to the edges of the cells. If there are infinitely many valid placements, you must report that as your answer.

Two placements are considered different if there exists a point that appears in one placement but not in the other.

입력

The first line of input contains two integers nn and qq (1≤n≤20001 ≤ n ≤ 2000, 1≤q≤100,0001 ≤ q ≤ 100\\, 000). The ii-th of the next qq lines contains a real number s_is\_i (0.01≤s_i≤n20.01 ≤ s\_i ≤ n^2), given with exactly two digits after the decimal point.

출력

Output qq lines. The ii-th line should contain the number of valid placements for query ii. If infinitely many exist, output -1 instead.

예제2

  1. 예제 1

    입력
    3 4
    6.90
    0.26
    2.65
    1.00
    
    예상 출력
    2
    4
    10
    -1
    
  2. 예제 2

    입력
    1 5
    0.49
    0.50
    0.51
    0.99
    1.00
    
    예상 출력
    0
    1
    2
    2
    1