6 kyu
How Many Differences of Squares?
160 of 325emaclean
Description:
Some numbers can be expressed as a difference of two squares, for example, 20 = 62-42
and 21 = 52-22
. Many numbers can be written this way, but not all.
Your Task
Complete the function that takes a positive integer n
and returns the amount of numbers between 1
and n
(inclusive) that can be represented as the difference of two perfect squares.
Note: Your code should be able to handle n
values up to 45000
Examples
n = 4 ==> 3
n = 5 ==> 4
n = 10 ==> 7
n = 20 ==> 15
n = 6427 ==> 4820
Mathematics
Algorithms
Similar Kata:
Stats:
Created | May 14, 2018 |
Published | May 15, 2018 |
Warriors Trained | 1113 |
Total Skips | 44 |
Total Code Submissions | 1300 |
Total Times Completed | 325 |
JavaScript Completions | 102 |
Python Completions | 160 |
Haskell Completions | 25 |
Ruby Completions | 28 |
Java Completions | 62 |
R Completions | 27 |
Total Stars | 31 |
% of votes with a positive feedback rating | 90% of 87 |
Total "Very Satisfied" Votes | 74 |
Total "Somewhat Satisfied" Votes | 9 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |