How to resolve the algorithm Sequence of non-squares step by step in the Picat programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sequence of non-squares step by step in the Picat programming language
Table of Contents
Problem Statement
Show that the following remarkable formula gives the sequence of non-square natural numbers:
This is sequence A000037 in the OEIS database.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sequence of non-squares step by step in the Picat programming language
Source code in the picat programming language
go =>
println([f(I) : I in 1..22]),
nl,
check(1_000_000),
nl.
% The formula
f(N) = N + floor(1/2 + sqrt(N)).
check(Limit) =>
Squares = new_map([I*I=1:I in 1..sqrt(Limit)]),
Check = [[I,T] : I in 1..Limit-1, T=f(I), Squares.has_key(T)],
println(check=Check.len).
You may also check:How to resolve the algorithm Jacobsthal numbers step by step in the Java programming language
You may also check:How to resolve the algorithm Probabilistic choice step by step in the Forth programming language
You may also check:How to resolve the algorithm Validate International Securities Identification Number step by step in the langur programming language
You may also check:How to resolve the algorithm Faulhaber's formula step by step in the Go programming language
You may also check:How to resolve the algorithm Unbias a random generator step by step in the Common Lisp programming language