Unit Squares Along a Diagonal

Time limit1sMemory limit128 MB

Summary
Given N, count unordered integer side pairs (a,b) such that a+b-gcd(a,b) equals N, using the diagonal-crossing formula for a grid rectangle.
Level

Medium6 of 10

Topics
Number theory, Math, Combinatorics
Solved
No attempts yet

Problem

RR is a rectangle whose side lengths are integers. It can be tiled exactly by unit squares, each with side length 11.

Define f(R)f(R) as the number of unit squares that one diagonal of the rectangle RR passes through. For example, a rectangle with side lengths 22 and 44 has f(R)=4f(R) = 4.

Given a natural number NN, count the number of rectangles RR that satisfy f(R)=Nf(R) = N. A rectangle with side lengths aa and bb is considered the same as one with side lengths bb and aa.

Input

The first line contains a natural number NN (0<N<1060 < N < 10^6).

Output

Print the number of rectangles RR satisfying f(R)=Nf(R) = N on the first line.

Hint

Think about how to express, using only the two side lengths aa and bb, the number of unit squares that the diagonal of an a×ba \times b rectangle passes through.

Examples2

  1. Example 1

    Input
    4
    
    Expected output
    4
    
  2. Example 2

    Input
    1
    
    Expected output
    1