Can you plz answer this question doors algorithm let's assume there are n number of doors number from 1 to n, initially all doors are closed. all these doors were connected to wireless switching system. the doors can be opened or closed only by the switching system. this system performs a certain algorithm to open and close the doors example: let's consider (n=5) 5 doors which are initially closed. now the system performs the algorithm for n number of iterations in this case 5. iteration 1: "each door number which are divisible by 1 is toggled", currently all doors are closed, and all numbers from 1 to 5 is divisible by 1 so all doors are opened. so after iteration 1 the doors which are open is 1,2,3,4,5 iteration 2: "each door number which are divisible by 2 is toggled", now the numbers divisible by 2 from 1 to 5 are 2,4. these doors alone be toggled so after iteration 2 the doors which are open is 1,3,5 and doors which are closed are 2,4 iteration 3: "each door number which are divisible by 3 is toggled", now the numbers divisible by 3 from 1 to 5 are 3, these door alone be toggled, so previously 3 is opened now it is closed so after iteration 3 the doors which are open is 1,5 and doors which are closed are 2,3,4 iteration 4: "each door number which are divisible by 4 is toggled" now the number divisible by 4 in 1 to 5 is only 4 which is only be toggled, so previously 4 is closed now it is opened so after iteration 4 the doors which are open is 1,4,5 and doors which are closed are 2,3 iteration 5: "each door number which are divisible by 5 is toggled", now the numbers divisible by 5 from 1 to 5 are 5, these door alone be toggled, so previously 5 is opened now it is closed so after iteration 5 the doors which are open is 1,4 and doors which are closed are 2,3,5 after all 5 iterations the result is the doors opened 1,4 and doors closed: 2,3,5 sample input and output: 1) n=10=> opened doors =[1,4,9] closed doors = [2,3,5,6,7,8,10] 2)n=15=> opened doors =[1,4,9] closed doors = [2,3,5,6,7,8,10,11,12,13,14,15]
Thank u. I get the logic easily, expecting more vedios❤
Welcome
Watch my other videos here:
Java Tutorial Playlist with Java programs:
ruclips.net/p/PLhyraTKIsw5_WemVMvshNm-0aC7zfISCO&si=Fe1e2FqEFmCeHQDX
Thank you sir 🤗🤗🤗
Most welcome
Very well explained
Thanks for liking
Can you plz answer this question
doors algorithm let's assume there are n number of doors number from 1 to n, initially all doors are closed. all these doors were connected to wireless switching system. the doors can be opened or closed only by the switching system. this system performs a certain algorithm to open and close the doors example: let's consider (n=5) 5 doors which are initially closed. now the system performs the algorithm for n number of iterations in this case 5. iteration 1: "each door number which are divisible by 1 is toggled", currently all doors are closed, and all numbers from 1 to 5 is divisible by 1 so all doors are opened. so after iteration 1 the doors which are open is 1,2,3,4,5 iteration 2: "each door number which are divisible by 2 is toggled", now the numbers divisible by 2 from 1 to 5 are 2,4. these doors alone be toggled so after iteration 2 the doors which are open is 1,3,5 and doors which are closed are 2,4 iteration 3: "each door number which are divisible by 3 is toggled", now the numbers divisible by 3 from 1 to 5 are 3, these door alone be toggled, so previously 3 is opened now it is closed so after iteration 3 the doors which are open is 1,5 and doors which are closed are 2,3,4 iteration 4: "each door number which are divisible by 4 is toggled" now the number divisible by 4 in 1 to 5 is only 4 which is only be toggled, so previously 4 is closed now it is opened so after iteration 4 the doors which are open is 1,4,5 and doors which are closed are 2,3 iteration 5: "each door number which are divisible by 5 is toggled", now the numbers divisible by 5 from 1 to 5 are 5, these door alone be toggled, so previously 5 is opened now it is closed so after iteration 5 the doors which are open is 1,4 and doors which are closed are 2,3,5 after all 5 iterations the result is the doors opened 1,4 and doors closed: 2,3,5
sample input and output: 1) n=10=> opened doors =[1,4,9] closed doors = [2,3,5,6,7,8,10] 2)n=15=> opened doors =[1,4,9] closed doors = [2,3,5,6,7,8,10,11,12,13,14,15]
My head hurts
You are too fast bro
Ok thanks for feedback. Will improve 👍
Error codes