Advertisement
ivan_yosifov

One_Task_Is_Not_Enough

Jan 3rd, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4.  
  5. class Program
  6. {
  7.     static int GetLastLampIndex(bool[] lamps)
  8.     {
  9.         int length = lamps.Length;
  10.         int count = length;
  11.  
  12.         for (int i = 0; i < length; i++)
  13.         {
  14.             int step = i + 2;
  15.             for (int j = i; j < length; j += step)
  16.             {
  17.                 if (lamps[j] == false)
  18.                 {
  19.                     lamps[j] = true;
  20.                     count--;
  21.                     if (count == 0)
  22.                     {
  23.                         return (j + 1);
  24.                     }
  25.                 }
  26.             }
  27.         }
  28.         return 0;
  29.        
  30.     }
  31.  
  32.     static void Main()
  33.     {
  34.         int N = int.Parse(Console.ReadLine());
  35.        
  36.         bool[] lamps = new bool[N];
  37.  
  38.         int lastLampIndex = GetLastLampIndex(lamps);
  39.         Console.WriteLine(lastLampIndex);
  40.                
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement