problem set 1. I don't know how to generate all odd integers. Anyone? I just have no clue.
Hint: mod 2 = 1 then it's odd.
So how do you refer to all of the odds? I don't want to make an arbitrary range.
You need to specify the range of integers if you want to find a set of odd integers in that range.
In the hints for this question (pset 1) it says to "generate all odd integers > 1 as candidates to be prime." I wanted to avoid using something like range(1000000). I just can't figure out the looping construct. Feeling pretty lame...
just put the given condition in a loop but remember it will be an infinite loop as there are infinite odd numbers.
in a simple for loop you can write, for(int i; ;i+=2) { [ print the value of 'i' according to your programming language ] }
You don't need to generate the odd integers as a totally separate step. You need to generate the next odd integer, when it's needed, to be a candidate for being prime.
n*2+1
Join our real-time social learning platform and learn together with your friends!