Skip to content

Instantly share code, notes, and snippets.

@Sarverott
Created February 19, 2026 05:49
Show Gist options
  • Select an option

  • Save Sarverott/1b640e4c5b71ec51e7bfb084abe66db6 to your computer and use it in GitHub Desktop.

Select an option

Save Sarverott/1b640e4c5b71ec51e7bfb084abe66db6 to your computer and use it in GitHub Desktop.
test with logical trap that can lead to make wrong assumptions if never tested results of algorithm

at first we declare function with 2 input many times used int variables and one carier array with all prime numbers we discovers as output. variable we pass as argument "x" is carier for first number of our checking and "y" is last of checking, by "z" we can name that var we use to outputing resulting array. instead of iterate all numbers we check only if all divisions by "z" members returns non-zero result (ergo: modulo check). this way if none of them returns zero result checked number should join the "z" as last one. if it detect zero it is skipped to next one (increment "i"). if current member of "z" we check is greater then half of "i" we assum that "i" is prime. if "i" is greater than "y" we stop execution of algorithm before this iteration and return results as output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment