#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @File Name: problem173.py
# @Author: Copyright (c) 2016-10-07 12:31:35 Gillett Hernandez
# @Date:   2016-10-07 12:31:35
# @Last Modified by:   Gillett Hernandez
# @Last Modified time: 2017-08-10 12:37:04

# MARK SLOW

import euler_funcs as ef
from euler_funcs import timed

def divisors(n):
    ds = []
    sum_of_divisors(n, lambda d: ds.append(d) or 1)
    ds.sort()
    return ds

def sum_of_divisors(n, func=lambda x: x):
    s = 1
    sqrtn = 1+int(n**(0.5))
    for i in range(2, sqrtn):
        if n % i == 0 and n // i != i:
            s += func(i)
            s += func(n//i)
        elif n % i == 0 and n // i == i:
            s += func(i)
    return s

def number_hollow_laminae(n):
    S = 0
    # for a hollow laminae to form
    # one must have that 2|a and  2|b or
    #                   ~2|a and ~2|b
    # thus a + b must be even and so is a-b
    # thus (a + b) * (a - b) is even
    # also (a + b) + (a - b) is even
    #ab_s = []
    for i in range(8,n+1,2):
        # (a-b)(a+b) = i
        for d in divisors(i):
            i_d = i//d
            if d >= i_d:
                break
            a2 = (d+i_d)
            if a2 & 1 == 1:
                continue
            #a = a2//2
            #Md = max(d, i_d)
            #b = Md - a
            S += 1
            #print(d,i_d)
            #ab_s.append((a, b))
    return S#, ab_s

@timed
def main():
    # fast solution runs in 1.7s in pypy with swapping xrange and range
    # S = 0
    # for i in range(2,25*10**4+1):
    #     S += (ef.divisor_count(i)+1)//2
    # print(S)
    # slower solution runs in 8s in pypy while swapping xrange and range
    print(number_hollow_laminae(1000000))

if __name__ == '__main__':
    main()
