Project Euler #174: Counting the number of "hollow" square laminae that can form one, two, three, ... distinct arrangements.

  • + 0 comments

    As 100% solutions are already posted, here is in Java :

    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.PrintStream;
    import java.util.Scanner;
    
    public class Solution {
      public static void main(String[] args) throws Exception {
        final int[] s = new int[250_001];
        for (int h = 1; h < 501; h++)
          for (int p = h * h + h; p < s.length; p += h)
            s[p]++;
    
        for (int i = 2, sum = 0; i < s.length; i++)
          s[i] = sum += s[i] <= 10 ? 1 : 0;
    
        try (Scanner in = new Scanner(new BufferedInputStream(System.in))) {
          try (PrintStream out = new PrintStream(new BufferedOutputStream(System.out))) {
            for (int T = in.nextInt(); T > 0; T--)
              out.println(s[in.nextInt() >> 2]);
          }
        }
      }
    }