Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Collections.Generic;
- class Program
- {
- static int GetLastLampIndex(bool[] lamps)
- {
- int length = lamps.Length;
- int count = length;
- for (int i = 0; i < length; i++)
- {
- int step = i + 2;
- for (int j = i; j < length; j += step)
- {
- if (lamps[j] == false)
- {
- lamps[j] = true;
- count--;
- if (count == 0)
- {
- return (j + 1);
- }
- }
- }
- }
- return 0;
- }
- static void Main()
- {
- int N = int.Parse(Console.ReadLine());
- bool[] lamps = new bool[N];
- int lastLampIndex = GetLastLampIndex(lamps);
- Console.WriteLine(lastLampIndex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement