### Counting the number of "hollow" square laminae that can form one, two, three, ... distinct arrangements题号：174 难度： 40 中英对照

We shall define a square lamina to be a square outline with a square "hole" so that the shape possesses vertical and horizontal symmetry.

Given eight tiles it is possible to form a lamina in only one way: 3x3 square with a 1x1 hole in the middle. However, using thirty-two tiles it is possible to form two distinct laminae.

If t represents the number of tiles used, we shall say that t = 8 is type L(1) and t = 32 is type L(2).

Let N(n) be the number of t ≤ 1000000 such that t is type L(n); for example, N(15) = 832.

What is ∑ N(n) for 1 ≤ n ≤ 10?

### Code

import java.util.Arrays;

public final class p174 {
private static final int MAX_N=1000000;
public static void main(String[] args){
long start=System.nanoTime();
long result = run();
long end=System.nanoTime();
System.out.println(result);
System.out.println( (end-start)/1000000 + "ms" );
}
public static long run(){
int[] N=new int[MAX_N+1];
Arrays.fill(N,0);
for(int n=3;(n-1)*4<=MAX_N;n++){
for(int m=n-2;m>=1;m=m-2){
int number=n*n-m*m;
if(number>MAX_N){
break;
}
N[number]++;
}
}
long ans=0;
for(int i=0;i<=MAX_N;i++){
if(N[i]>=1&&N[i]<=10){
ans++;
}
}
return ans;
}
}

209566
39ms