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

More By Author:

Check out these other kata created by emaclean

Stats:

CreatedMay 14, 2018
PublishedMay 15, 2018
Warriors Trained1113
Total Skips44
Total Code Submissions1300
Total Times Completed325
JavaScript Completions102
Python Completions160
Haskell Completions25
Ruby Completions28
Java Completions62
R Completions27
Total Stars31
% of votes with a positive feedback rating90% of 87
Total "Very Satisfied" Votes74
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes4
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • emaclean Avatar
  • raulbc777 Avatar
  • anter69 Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad