Challenges (Prateek loves Candy)

i tried understanding the SOE algorithm …i understoood the basic idea behind it but the code is a bit confusing …Also i downloaded the editorial for the question but its in c++ maybe so i am not able to understand that …Please help me understand the solution

in soe the basic idea is to cancel out all the numbers that aren’t prime by dividing all the numbers in range by sqrt(number) , the remaining numbers are prime.

For eg :
if we want to find out prime numbers between 1 to 100 , we will first take sqrt(100) which is 10 , then we will divide every number from 1 to 100 with each of the numbers from 1 to 10 . The remaining numbers are prime.