Given an integer N, the task is to find the count of squares of side 1 that can be drawn without lifting the pencil, starting at one corner of an N * N grid and never visiting an edge twice.
Input: N = 2
Input: N = 3
Approach: It can be observed that for the values of N = 1, 2, 3, …, a series will be formed as 1, 2, 5, 10, 17, 26, 37, 50, … whose Nth term is (N2 – (2 * N) + 2)
Below is the implementation of the above approach:
Time Complexity: O(1)
- Count digits in a factorial | Set 2
- Count of Binary Digit numbers smaller than N
- Count numbers that don't contain 3
- Count the number of possible triangles
- Count numbers with same first and last digits
- Count digits in given number N which divide N
- Count all possible paths from top left to bottom right of a mXn matrix
- Count trailing zeroes in factorial of a number
- Count Possible Decodings of a given Digit Sequence
- Count ways to reach the n'th stair
- Print squares of first n natural numbers without using *, / and -
- Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x + y*y < n
- Count inversions in an array | Set 3 (Using BIT)
- Count numbers from 1 to n that have 4 as a digit
- Count factorial numbers in a given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.