Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <utility>
- using namespace std;
- /*
- In an imaginary high school there exist 1000 lockers labelled 1, 2, ..., 1000.
- All of them are closed. 1000 students are to "toggle" a locker's state.
- * The first student toggles all of them * The second one toggles every other
- one (i.e, 2, 4, 6, ...) * The third one toggles the multiples of 3 (3, 6, 9, ...)
- and so on until all students have finished.
- To toggle means to close the locker if it is open, and to open it if it's closed.
- How many and which lockers are open in the end?
- */
- int main()
- {
- int temp = 0;
- for( int x = 0; x != 1000; x++ )
- {
- for( int y = 1; y <= x; y++ )
- {
- if( x % y == 0 )
- {
- temp++;
- }
- }
- if( temp % 2 == 0 )
- {
- }
- else
- {
- cout << x << ", ";
- }
- temp = 0;
- }
- cout << "\n\nDone.\n\n";
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement